From 27a57bdafbb396c010480d85c194c4814da47fa4 Mon Sep 17 00:00:00 2001 From: Karl W Schulz Date: Fri, 8 Mar 2024 17:20:08 -0600 Subject: [PATCH] refactor setting of local encoding; remove from top-level omniperf wrapper and push into base class via a companion utility function Signed-off-by: Karl W Schulz --- src/omniperf | 11 ++--------- src/omniperf_base.py | 2 ++ src/utils/utils.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/omniperf b/src/omniperf index a27946a332..3cd3f2f840 100755 --- a/src/omniperf +++ b/src/omniperf @@ -25,23 +25,16 @@ ##############################################################################el import sys -import locale import logging -from utils.utils import error from omniperf_base import Omniperf from utils.utils import console_error def main(): - try: - locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') - except locale.Error as e: - logging.warning("Please ensure that the 'en_US.UTF-8' locale is available on your system.") - error(f"Error setting locale: {e}") omniperf = Omniperf() - + mode = omniperf.get_mode() - + # major omniperf execution modes if mode == "profile": omniperf.run_profiler() diff --git a/src/omniperf_base.py b/src/omniperf_base.py index 292f576e2d..26b26a7188 100644 --- a/src/omniperf_base.py +++ b/src/omniperf_base.py @@ -38,6 +38,7 @@ from utils.utils import ( console_debug, console_log, console_error, + set_locale_encoding, ) from utils.logger import setup_console_handler, setup_logging_priority, setup_file_handler from argparser import omniarg_parser @@ -57,6 +58,7 @@ SUPPORTED_ARCHS = { class Omniperf: def __init__(self): + set_locale_encoding() self.__args = None self.__profiler_mode = None self.__analyze_mode = None diff --git a/src/utils/utils.py b/src/utils/utils.py index d2a884fc11..b17c98b353 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -22,6 +22,7 @@ # SOFTWARE. ##############################################################################el +import locale import logging import sys import os @@ -593,3 +594,13 @@ def print_status(msg): console_log(msg) console_log("~" * (msg_length + 1)) console_log("") + + +def set_locale_encoding(): + try: + locale.setlocale(locale.LC_ALL, "en_US.UTF-8") + except locale.Error as error: + print("Please ensure that the 'en_US.UTF-8' locale is available on your system.") + print("") + print("ERROR: ", error) + sys.exit(1)