locale helpers are now on their own file

This commit is contained in:
Félix Boisselier
2023-12-26 23:47:14 +01:00
parent f385bd98e3
commit 0ff63edec8
5 changed files with 52 additions and 91 deletions

View File

@@ -13,31 +13,13 @@
import optparse
import numpy as np
import locale
from locale_utils import print_with_c_locale
from scipy.signal import butter, filtfilt
NUM_POINTS = 500
# Set the best locale for time and date formating (generation of the titles)
try:
current_locale = locale.getlocale(locale.LC_TIME)
if current_locale is None or current_locale[0] is None:
locale.setlocale(locale.LC_TIME, 'C')
except locale.Error:
locale.setlocale(locale.LC_TIME, 'C')
# Override the built-in print function to avoid problem in Klipper due to locale settings
original_print = print
def print_with_c_locale(*args, **kwargs):
original_locale = locale.setlocale(locale.LC_ALL, None)
locale.setlocale(locale.LC_ALL, 'C')
original_print(*args, **kwargs)
locale.setlocale(locale.LC_ALL, original_locale)
print = print_with_c_locale
######################################################################
# Computation
######################################################################
@@ -162,7 +144,7 @@ def main():
opts.error("Invalid acceleration value. It should be a numeric value.")
results = axesmap_calibration(args, accel_value)
print(results)
print_with_c_locale(results)
if options.output is not None:
with open(options.output, 'w') as f: