Skip to content

Commit

Permalink
refactor setting of local encoding; remove from top-level omniperf
Browse files Browse the repository at this point in the history
wrapper and push into base class via a companion utility function

Signed-off-by: Karl W Schulz <karl.schulz@amd.com>
  • Loading branch information
koomie committed Mar 8, 2024
1 parent 6bcf3e3 commit 3c67670
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/omniperf
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/omniperf_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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
Expand All @@ -57,6 +58,7 @@

class Omniperf:
def __init__(self):
set_locale_encoding()
self.__args = None
self.__profiler_mode = None
self.__analyze_mode = None
Expand Down
11 changes: 11 additions & 0 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# SOFTWARE.
##############################################################################el

import locale
import logging
import sys
import os
Expand Down Expand Up @@ -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)

0 comments on commit 3c67670

Please sign in to comment.