From: Kamalesh Babulal Date: Wed, 23 Feb 2022 09:38:48 +0000 (+0530) Subject: log.py: fix selfimport X-Git-Tag: v3.1.0~308^2~2^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aee2ed3cd0e04fc0bc6564bb16a32c68f5583e90;p=thirdparty%2Flibcgroup.git log.py: fix selfimport It's not advised to selfimport, i.e import log. To remove this selfimport, the global variable access needs to be fixed by using 'global' keyword inside the Class methods. Reported-by: LGTM Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/ftests/log.py b/ftests/log.py index 4f8543d9..6f9c9134 100644 --- a/ftests/log.py +++ b/ftests/log.py @@ -21,7 +21,6 @@ import datetime import consts -import log log_level = consts.DEFAULT_LOG_LEVEL log_file = consts.DEFAULT_LOG_FILE @@ -32,16 +31,20 @@ class Log(object): @staticmethod def log(msg, msg_level=consts.DEFAULT_LOG_LEVEL): + global log_level, log_file, log_fd + if log_level >= msg_level: - if log.log_fd is None: - Log.open_logfd(log.log_file) + if log_fd is None: + Log.open_logfd(log_file) timestamp = datetime.datetime.now().strftime('%b %d %H:%M:%S') log_fd.write('{}: {}\n'.format(timestamp, msg)) @staticmethod def open_logfd(log_file): - log.log_fd = open(log_file, 'a') + global log_fd + + log_fd = open(log_file, 'a') @staticmethod def log_critical(msg):