From 32a175aba695ed0fb3bd3da9efd9f537ac371797 Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Tue, 18 Jun 2024 17:28:50 +0200 Subject: [PATCH 1/2] Add shutdown and full export setting --- cuvis/FileWriteSettings.py | 5 ++++- cuvis/General.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cuvis/FileWriteSettings.py b/cuvis/FileWriteSettings.py index 8055604..de72e9d 100644 --- a/cuvis/FileWriteSettings.py +++ b/cuvis/FileWriteSettings.py @@ -143,6 +143,7 @@ class SaveArgs(GeneralExportSettings): soft_limit: int = 20 hard_limit: int = 100 max_buftime: int = 10000 + full_export: bool = False def _get_internal(self): ge = super()._get_internal() @@ -157,6 +158,7 @@ def _get_internal(self): sa.soft_limit = int(self.soft_limit) sa.hard_limit = int(self.hard_limit) sa.max_buftime = int(self.max_buftime) + sa.full_export = int(self.full_export) return ge, sa @classmethod @@ -172,7 +174,8 @@ def _from_internal(cls, ge, sa): fps = sa.fps, soft_limit = sa.soft_limit, hard_limit = sa.hard_limit, - max_buftime = sa.max_buftime + max_buftime = sa.max_buftime, + full_export = sa.full_export ) @dataclass diff --git a/cuvis/General.py b/cuvis/General.py index 6dda23a..62ba902 100644 --- a/cuvis/General.py +++ b/cuvis/General.py @@ -35,7 +35,9 @@ def __init__(self, settings_path:str=".", log_path:str="", global_loglevel:int=l if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel]): raise SDKException() - pass + + def __del__(self): + cuvis_il.cuvis_shutdown() @property def version(self) -> str: From 618e26f248bd3b7bf6f268a046d73357f0def1b8 Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Wed, 19 Jun 2024 10:25:08 +0200 Subject: [PATCH 2/2] Remove class Generic --- cuvis/General.py | 85 +++++++++++++++++++++++------------------------ cuvis/__init__.py | 2 +- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/cuvis/General.py b/cuvis/General.py index 62ba902..b03a3ba 100644 --- a/cuvis/General.py +++ b/cuvis/General.py @@ -10,54 +10,53 @@ from dataclasses import dataclass -class General(object): - def __init__(self, settings_path:str=".", log_path:str="", global_loglevel:int=logging.DEBUG): - FORMAT = '%(asctime)s -- %(levelname)s: %(message)s' - if os.path.exists(log_path): - pass - elif platform.system() == "Linux": - log_path = os.path.join(os.path.expanduser('~'), ".cuvis") - os.makedirs(log_path, exist_ok=True) - elif platform.system() == "Windows": - log_path = "C:\\ProgramData\\cuvis" - os.makedirs(log_path, exist_ok=True) - - if os.path.exists(log_path): - logging.basicConfig(filename= os.path.join(log_path, "cuvisSDK_python.log"), - format=FORMAT, - encoding='utf-8', - level=global_loglevel, - filemode='w') - else: - raise SDKException( - "path {} does not exist...".format(os.path.abspath(log_path))) - logging.info("Logger ready.") - if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel]): - raise SDKException() +def init(settings_path:str=".", log_path:str="", global_loglevel:int=logging.DEBUG): + FORMAT = '%(asctime)s -- %(levelname)s: %(message)s' + if os.path.exists(log_path): + pass + elif platform.system() == "Linux": + log_path = os.path.join(os.path.expanduser('~'), ".cuvis") + os.makedirs(log_path, exist_ok=True) + elif platform.system() == "Windows": + log_path = "C:\\ProgramData\\cuvis" + os.makedirs(log_path, exist_ok=True) - def __del__(self): - cuvis_il.cuvis_shutdown() + if os.path.exists(log_path): + logging.basicConfig(filename= os.path.join(log_path, "cuvisSDK_python.log"), + format=FORMAT, + encoding='utf-8', + level=global_loglevel, + filemode='w') + else: + raise SDKException( + "path {} does not exist...".format(os.path.abspath(log_path))) + logging.info("Logger ready.") - @property - def version(self) -> str: - return cuvis_il.cuvis_version_swig() + if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel]): + raise SDKException() - def set_log_level(self, lvl): - lvl_dict = {"info": {"cuvis": cuvis_il.loglevel_info, - "logging": logging.INFO}, - "debug": {"cuvis": cuvis_il.loglevel_debug, - "logging": logging.DEBUG}, - "error": {"cuvis": cuvis_il.loglevel_error, - "logging": logging.ERROR}, - "fatal": {"cuvis": cuvis_il.loglevel_fatal, - "logging": logging.CRITICAL}, - "warning": {"cuvis": cuvis_il.loglevel_warning, - "logging": logging.WARNING}, - } +def shutdown(): + cuvis_il.cuvis_shutdown() - cuvis_il.cuvis_set_log_level(lvl_dict[lvl]["cuvis"]) - logging.basicConfig(level=lvl_dict[lvl]["logging"]) +def version() -> str: + return cuvis_il.cuvis_version_swig() + +def set_log_level(lvl): + lvl_dict = {"info": {"cuvis": cuvis_il.loglevel_info, + "logging": logging.INFO}, + "debug": {"cuvis": cuvis_il.loglevel_debug, + "logging": logging.DEBUG}, + "error": {"cuvis": cuvis_il.loglevel_error, + "logging": logging.ERROR}, + "fatal": {"cuvis": cuvis_il.loglevel_fatal, + "logging": logging.CRITICAL}, + "warning": {"cuvis": cuvis_il.loglevel_warning, + "logging": logging.WARNING}, + } + + cuvis_il.cuvis_set_log_level(lvl_dict[lvl]["cuvis"]) + logging.basicConfig(level=lvl_dict[lvl]["logging"]) @dataclass diff --git a/cuvis/__init__.py b/cuvis/__init__.py index af7e0b9..5c839fc 100644 --- a/cuvis/__init__.py +++ b/cuvis/__init__.py @@ -24,7 +24,7 @@ ProcessingArgs, \ EnviExportSettings, TiffExportSettings, ViewExportSettings, \ WorkerSettings -from .General import General +from .General import init, shutdown, version, set_log_level from .Measurement import Measurement from .ProcessingContext import ProcessingContext from .SessionFile import SessionFile