Make log filename machine-dependent

Move kernel args parsing
main
Vadim vtroshchinskiy 2024-12-16 13:07:28 +01:00
parent 655dfbb049
commit bcf376ab82
2 changed files with 32 additions and 22 deletions

View File

@ -291,28 +291,7 @@ class OpengnsysGitLibrary:
f.write("\n".join(self.default_ignore_list)) f.write("\n".join(self.default_ignore_list))
f.write("\n") f.write("\n")
def _parse_kernel_cmdline(self):
"""Parse the kernel arguments to obtain configuration parameters in Oglive
OpenGnsys passes data in the kernel arguments, for example:
[...] group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 [...]
Returns:
dict: Dict of configuration parameters and their values.
"""
params = {}
self.logger.debug("Parsing kernel parameters")
with open("/proc/cmdline", encoding='utf-8') as cmdline:
line = cmdline.readline()
parts = line.split()
for part in parts:
if "=" in part:
key, value = part.split("=")
params[key] = value
self.logger.debug("%i parameters found", len(params))
return params
@ -1544,6 +1523,9 @@ if __name__ == '__main__':
# esto arregla las tildes y las eñes # esto arregla las tildes y las eñes
sys.stdout.reconfigure(encoding='utf-8') sys.stdout.reconfigure(encoding='utf-8')
kernel_args = parse_kernel_cmdline()
opengnsys_log_dir = "/opt/opengnsys/log" opengnsys_log_dir = "/opt/opengnsys/log"
logger = logging.getLogger(__package__) logger = logging.getLogger(__package__)
@ -1555,7 +1537,13 @@ if __name__ == '__main__':
if not os.path.exists(opengnsys_log_dir): if not os.path.exists(opengnsys_log_dir):
os.mkdir(opengnsys_log_dir) os.mkdir(opengnsys_log_dir)
logFilePath = f"{opengnsys_log_dir}/gitlib.log" ip_address = "unknown"
if "ip" in kernel_args:
ip_address = kernel_args["ip"].split(":")[0]
logFilePath = f"{opengnsys_log_dir}/{ip_address}.gitlib.log"
fileLog = logging.FileHandler(logFilePath) fileLog = logging.FileHandler(logFilePath)
fileLog.setLevel(logging.DEBUG) fileLog.setLevel(logging.DEBUG)

22
gitlib/kernel.py 100644
View File

@ -0,0 +1,22 @@
def parse_kernel_cmdline():
"""Parse the kernel arguments to obtain configuration parameters in Oglive
OpenGnsys passes data in the kernel arguments, for example:
[...] group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 [...]
Returns:
dict: Dict of configuration parameters and their values.
"""
params = {}
with open("/proc/cmdline", encoding='utf-8') as cmdline:
line = cmdline.readline()
parts = line.split()
for part in parts:
if "=" in part:
key, value = part.split("=")
params[key] = value
return params