Index: leahi_dialin/common/__init__.py =================================================================== diff -u -r2138d06d100fdcf23f2e9069f35ee2fdee62008f -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/common/__init__.py (.../__init__.py) (revision 2138d06d100fdcf23f2e9069f35ee2fdee62008f) +++ leahi_dialin/common/__init__.py (.../__init__.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -1,6 +1,26 @@ -from .alarm_defs import * -from .alarm_priorities import * +import os +import json + +# mandatory import from .msg_defs import * -from .td_defs import * -from .dd_defs import * -from .ui_defs import * + +file_name = "config.json" +sw_key = "SW" +config = {} +ok: bool = False +module_name = os.path.basename(os.getcwd()) + +try: + with open(file_name, 'r') as file: config = json.load(file); ok = config[sw_key] +except FileNotFoundError: print(f"Error ({module_name}): The file '{file_name}' was not found." ) +except KeyError : print(f"Error ({module_name}): The key '{sw_key}' was not found." ) +except Exception as e : print(f"Error ({module_name}): An unexpected error occurred: {e}" ) + +if ok: + print(f"{sw_key} is set to bypass the auto imports.") +else: + from .alarm_defs import * + from .alarm_priorities import * + from .td_defs import * + from .dd_defs import * + from .ui_defs import * Index: leahi_dialin/protocols/__init__.py =================================================================== diff -u -r2138d06d100fdcf23f2e9069f35ee2fdee62008f -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/protocols/__init__.py (.../__init__.py) (revision 2138d06d100fdcf23f2e9069f35ee2fdee62008f) +++ leahi_dialin/protocols/__init__.py (.../__init__.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -1,4 +1,22 @@ -from .CAN import DenaliCanMessenger -from .CAN import DenaliChannels -from .CAN import LongDenaliMessageBuilder -from .CAN import DenaliMessage +import os +import json + +file_name = "config.json" +sw_key = "SW" +config = {} +ok: bool = False +module_name = os.path.basename(os.getcwd()) + +try: + with open(file_name, 'r') as file: config = json.load(file); ok = config[sw_key] +except FileNotFoundError: print(f"Error ({module_name}): The file '{file_name}' was not found." ) +except KeyError : print(f"Error ({module_name}): The key '{sw_key}' was not found." ) +except Exception as e : print(f"Error ({module_name}): An unexpected error occurred: {e}" ) + +if ok: + print(f"{sw_key} is set to bypass the auto imports.") +else: + from .CAN import DenaliCanMessenger + from .CAN import DenaliChannels + from .CAN import LongDenaliMessageBuilder + from .CAN import DenaliMessage Index: leahi_dialin/ui/TD_Messaging.py =================================================================== diff -u -r9f44c02ff3f40812ab9fd7f9c7346f649a114c19 -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/ui/TD_Messaging.py (.../TD_Messaging.py) (revision 9f44c02ff3f40812ab9fd7f9c7346f649a114c19) +++ leahi_dialin/ui/TD_Messaging.py (.../TD_Messaging.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -1,21 +1,30 @@ #!/bin/python3 -from utils import singleton -from utils import conversions -from protocols import CAN -from common import msg_ids +from dialin.ui.utils import singleton_threadsafe +from dialin.utils import conversions +from dialin.protocols import CAN +from dialin.common import msg_ids +from dialin.utils import SingletonMeta +@singleton_threadsafe +class TD_Messaging(): -@singleton -class TD_Messaging: - - def __init__(self): self.can_enabled: bool=False self.can_Channel: str = "can0" - self.can_interface = CAN.DenaliCanMessenger(can_interface=self.can_Channel) + class fakeLogger(): + def __init__(self): + pass + + def error(a1, a2): + pass + + def info(a1, a2): + pass + + self.can_interface = CAN.DenaliCanMessenger(can_interface=self.can_Channel, logger=fakeLogger() ) self.can_interface.start() if self.can_interface is not None: Index: leahi_dialin/ui/utils.py =================================================================== diff -u -r9f44c02ff3f40812ab9fd7f9c7346f649a114c19 -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/ui/utils.py (.../utils.py) (revision 9f44c02ff3f40812ab9fd7f9c7346f649a114c19) +++ leahi_dialin/ui/utils.py (.../utils.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -17,23 +17,25 @@ import time import struct from subprocess import check_output +import threading -def singleton(cls): +def singleton_threadsafe(cls): """ This is a singleton decorator Returns: cls: as for defintion of the singleton, it created the class instance once and will return on each access, instead of the recreation. """ instances = {} + lock = threading.Lock() def get_instance(*args, **kwargs): - if cls not in instances: - instances[cls] = cls(*args, **kwargs) + with lock: + if cls not in instances: + instances[cls] = cls(*args, **kwargs) return instances[cls] return get_instance - def srsui(vstr=""): """ for user convenience if wanted to put a note for the SRSUI Index: leahi_dialin/utils/__init__.py =================================================================== diff -u -r2138d06d100fdcf23f2e9069f35ee2fdee62008f -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/utils/__init__.py (.../__init__.py) (revision 2138d06d100fdcf23f2e9069f35ee2fdee62008f) +++ leahi_dialin/utils/__init__.py (.../__init__.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -1,10 +1,30 @@ -from .base import * -from .checks import * -from .helpers import * -from .conversions import * -from .excel_ops import * -from .nv_ops_utils import * -from .singleton import * -from .data_logger import DataLogger -YES = 1 -NO = 0 +import os +import json + +# mandatory imports +from .base import * +from .singleton import * + +file_name = "config.json" +sw_key = "SW" +config = {} +ok: bool = False +module_name = os.path.basename(os.getcwd()) + +try: + with open(file_name, 'r') as file: config = json.load(file); ok = config[sw_key] +except FileNotFoundError: print(f"Error ({module_name}): The file '{file_name}' was not found." ) +except KeyError : print(f"Error ({module_name}): The key '{sw_key}' was not found." ) +except Exception as e : print(f"Error ({module_name}): An unexpected error occurred: {e}" ) + +if ok: + print(f"{sw_key} is set to bypass the auto imports.") +else: + from .conversions import * + from .data_logger import DataLogger + from .checks import * + from .helpers import * + from .excel_ops import * + from .nv_ops_utils import * + YES = 1 + NO = 0 Index: leahi_dialin/utils/data_logger.py =================================================================== diff -u -r2138d06d100fdcf23f2e9069f35ee2fdee62008f -r126c206228086fbd13e820980c2fbb2fb58131bb --- leahi_dialin/utils/data_logger.py (.../data_logger.py) (revision 2138d06d100fdcf23f2e9069f35ee2fdee62008f) +++ leahi_dialin/utils/data_logger.py (.../data_logger.py) (revision 126c206228086fbd13e820980c2fbb2fb58131bb) @@ -25,7 +25,7 @@ from pathlib import Path import pandas as pd -from leahi_dialin.utils.base import _FauxLogger +from ..utils.base import _FauxLogger class DataLogger: