]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
log.py: fix selfimport
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 23 Feb 2022 09:38:48 +0000 (15:08 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 24 Feb 2022 15:08:53 +0000 (08:08 -0700)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/log.py

index 4f8543d96eb329d0f36d52d026eda5a8f57f1990..6f9c913417a5d5bf3c7d60297c8d3a2caf55f88b 100644 (file)
@@ -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):