Skip to content

Commit

Permalink
global
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-usielski committed Feb 5, 2024
1 parent e36a2c7 commit 8ce0ca0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion moler/asyncio_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def start_async_coroutine(self, coroutine_to_run):
def get_asyncio_loop_thread():
logger = logging.getLogger('moler.asyncio-loop-thrd')
with _asyncio_loop_thread_lock:
global _asyncio_loop_thread
global _asyncio_loop_thread # pylint: disable=global-statement
if _asyncio_loop_thread is None:
logger.debug(">>> >>> found _asyncio_loop_thread as {}".format(_asyncio_loop_thread))

Expand Down
4 changes: 2 additions & 2 deletions moler/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def load_config(config=None, from_env_var=None, *args, **kwargs):
:param from_env_var: name of environment variable storing config filename (file is in YAML format)
:return: None
"""
global loaded_config
global loaded_config # pylint: disable=global-statement
add_devices_only = False
from moler.device import DeviceFactory

Expand Down Expand Up @@ -315,7 +315,7 @@ def reconfigure_logging_path(logging_path):

def clear():
"""Cleanup Moler's configuration"""
global loaded_config
global loaded_config # pylint: disable=global-statement
loaded_config = ["NOT_LOADED_YET"]
conn_cfg.clear()
dev_cfg.clear()
4 changes: 2 additions & 2 deletions moler/config/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def set_default_connection(io_type, variant):
"""Set connection to use as default when requesting 'device' without connection specification"""
global default_connection
global default_connection # pylint: disable=global-statement
default_connection = {"io_type": io_type, "variant": variant}


Expand Down Expand Up @@ -47,6 +47,6 @@ def define_device(

def clear():
"""Cleanup configuration related to devices"""
global default_connection
global default_connection # pylint: disable=global-statement
default_connection = {"io_type": "terminal", "variant": "threaded"}
named_devices.clear()
52 changes: 26 additions & 26 deletions moler/config/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def set_backup_count(backup_count):
:param backup_count: int number of how many files to keep to rotate logs.
:return: None
"""
global _backup_count
global _backup_count # pylint: disable=global-statement
try:
_backup_count = int(backup_count)
except ValueError:
Expand All @@ -134,7 +134,7 @@ def set_interval(interval):
:param interval: int number in bytes or seconds
:return: None
"""
global _interval
global _interval # pylint: disable=global-statement
try:
_interval = int(interval)
except ValueError:
Expand All @@ -147,7 +147,7 @@ def set_kind(kind):
:param kind: None for plain logger, 'time' to time rotating, 'size' for size rotating.
:return: None
"""
global _kind
global _kind # pylint: disable=global-statement
if kind is None:
_kind = None
kind = kind.lower()
Expand All @@ -161,7 +161,7 @@ def set_compress_after_rotation(compress_after_rotation):
:param compress_after_rotation: True to compress, False otherwsie
:return: None
"""
global _compress_after_rotation
global _compress_after_rotation # pylint: disable=global-statement
_compress_after_rotation = compress_after_rotation


Expand All @@ -171,7 +171,7 @@ def set_compress_command(compress_command):
:param compress_command: String with compress command with two fields {compressed} and {log_input}
:return: None
"""
global _compress_command
global _compress_command # pylint: disable=global-statement
_compress_command = compress_command


Expand All @@ -181,30 +181,30 @@ def set_compressed_file_extension(compressed_file_extension):
:param compressed_file_extension: String with file extension, for example ".zip"
:return: None
"""
global _compressed_file_extension
global _compressed_file_extension # pylint: disable=global-statement
_compressed_file_extension = compressed_file_extension


def set_write_mode(mode):
global write_mode
global write_mode # pylint: disable=global-statement
if mode.lower() in ["a", "append"]:
write_mode = "a"
elif mode.lower() in ["w", "write"]:
write_mode = "w"


def set_logging_path(path):
global _logging_path
global _logging_path # pylint: disable=global-statement
_logging_path = path


def get_logging_path():
global _logging_path
global _logging_path # pylint: disable=global-statement
return _logging_path


def set_date_format(format):
global date_format
global date_format # pylint: disable=global-statement
date_format = format


Expand All @@ -214,7 +214,7 @@ def configure_debug_level(level=None):
We use additional env variable besides MOLER_CONFIG to allow for quick/temporary change
since debug level is intended also for troubleshooting
"""
global debug_level
global debug_level # pylint: disable=global-statement
if level:
level_name = level
else:
Expand All @@ -234,7 +234,7 @@ def set_error_log_stack(error_log_stack=False):
:param error_log_stack: True to get all functions, False to get the last one.
:return: None
"""
global _error_log_stack
global _error_log_stack # pylint: disable=global-statement
_error_log_stack = error_log_stack


Expand All @@ -243,7 +243,7 @@ def get_error_log_stack():
Get how many functions stack you want to log when error is logged.
:return: True to get log of all
"""
global _error_log_stack
global _error_log_stack # pylint: disable=global-statement
return _error_log_stack


Expand All @@ -263,17 +263,17 @@ def change_logging_suffix(suffix=None, logger_name=None):
:param logger_name: name of logger. None for all loggers.
:return: None
"""
global _kind
global _kind # pylint: disable=global-statement
if _kind is not None:
global _main_logger
global _main_logger # pylint: disable=global-statement
if _main_logger is not None:
# noinspection PyUnresolvedReferences
_main_logger.info(
"Logs are rotated automatically: '{}'. Changing log suffixes is not"
" available now.".format(_kind)
)
return
global _logging_suffixes
global _logging_suffixes # pylint: disable=global-statement
_reopen_all_logfiles_with_new_suffix(
logger_suffixes=_logging_suffixes, new_suffix=suffix, logger_name=logger_name
)
Expand Down Expand Up @@ -387,13 +387,13 @@ def setup_new_file_handler(
:param filter: filter for file logger
:return: logging.FileHandler object
"""
global write_mode
global _kind
global _interval
global _backup_count
global _compress_after_rotation
global _compress_command
global _compressed_file_extension
global write_mode # pylint: disable=global-statement
global _kind # pylint: disable=global-statement
global _interval # pylint: disable=global-statement
global _backup_count # pylint: disable=global-statement
global _compress_after_rotation # pylint: disable=global-statement
global _compress_command # pylint: disable=global-statement
global _compressed_file_extension # pylint: disable=global-statement
logger = logging.getLogger(logger_name)
if _kind is None:
cfh = logging.FileHandler(log_filename, write_mode)
Expand Down Expand Up @@ -471,7 +471,7 @@ def _add_raw_file_handler(logger_name, log_file):
:param log_file: Path to logfile. Final logfile location is logging_path + log_file
:return: None
"""
global write_mode
global write_mode # pylint: disable=global-statement
logfile_full_path = os.path.join(_logging_path, log_file)
_prepare_logs_folder(logfile_full_path)
logger = logging.getLogger(logger_name)
Expand All @@ -486,7 +486,7 @@ def _add_raw_trace_file_handler(logger_name, log_file):
:param log_file: Path to logfile. Final logfile location is logging_path + log_file
:return: None
"""
global write_mode
global write_mode # pylint: disable=global-statement
logfile_full_path = os.path.join(_logging_path, log_file)
_prepare_logs_folder(logfile_full_path)
logger = logging.getLogger(logger_name)
Expand Down Expand Up @@ -568,7 +568,7 @@ def configure_moler_main_logger():
configure_moler_threads_logger()
logger.info("More logs in: {}".format(_logging_path))
_list_libraries(logger=logger)
global _main_logger
global _main_logger # pylint: disable=global-statement
_main_logger = logger


Expand Down
5 changes: 2 additions & 3 deletions moler/config/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected]'

import sys

default_variant = "threaded"


def set_default_variant(variant):
"""Set variant to use as default when requesting runner"""
global default_variant
global default_variant # pylint: disable=global-statement
default_variant = variant


def clear():
"""Cleanup configuration related to runners"""
global default_variant
global default_variant # pylint: disable=global-statement
default_variant = "threaded"


Expand Down
2 changes: 1 addition & 1 deletion moler/device/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, model='self', states=None, initial='initial', transitions=Non
self.logger.propagate = False
self.logger.setLevel(1)

global forwarding_handler
global forwarding_handler # pylint: disable=global-statement
if not forwarding_handler:
forwarding_handler = ForwardingHandler(target_logger_name="moler.state_machine")
self.logger.addHandler(forwarding_handler)
Expand Down

0 comments on commit 8ce0ca0

Please sign in to comment.