From 4fc692001571b286f0d491c8e714202cea277ba9 Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Fri, 9 Aug 2024 13:37:47 +0300 Subject: [PATCH] Windows compatibility for AppLogger & CWEDownloads (#301) * Conditionally import FullSysLogHandler Import FullSysLogHandler from CveXplore.core.logging.handlers.syslog_handler only if configured (for Windows compatibility). * CWEDownloads Windows compatibility fix --- .../database_maintenance/sources_process.py | 28 +++++++++---------- CveXplore/core/logging/logger_class.py | 6 +++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CveXplore/core/database_maintenance/sources_process.py b/CveXplore/core/database_maintenance/sources_process.py index cdec79d08..c4dc00692 100644 --- a/CveXplore/core/database_maintenance/sources_process.py +++ b/CveXplore/core/database_maintenance/sources_process.py @@ -997,22 +997,20 @@ def __init__(self): def file_to_queue(self, file_tuple: Tuple[str, str]): working_dir, filename = file_tuple - for f in glob.glob(f"{working_dir}/*.xml"): - filename = f - - self.parser.parse(f"file://{filename}") - x = 0 - for cwe in self.ch.cwe: - try: - cwe["related_weaknesses"] = list(set(cwe["related_weaknesses"])) - cwe["description"] = cwe["Description"] - cwe.pop("Description") - except KeyError: - pass - self.process_item(cwe) - x += 1 + for filename in glob.glob(f"{working_dir}/*.xml"): + self.parser.parse(filename) + x = 0 + for cwe in self.ch.cwe: + try: + cwe["related_weaknesses"] = list(set(cwe["related_weaknesses"])) + cwe["description"] = cwe["Description"] + cwe.pop("Description") + except KeyError: + pass + self.process_item(cwe) + x += 1 - self.logger.debug(f"Processed {x} entries from file: {filename}") + self.logger.debug(f"Processed {x} entries from file: {filename}") try: self.logger.debug(f"Removing working dir: {working_dir}") diff --git a/CveXplore/core/logging/logger_class.py b/CveXplore/core/logging/logger_class.py index 2d04b3f67..1b3703d5f 100644 --- a/CveXplore/core/logging/logger_class.py +++ b/CveXplore/core/logging/logger_class.py @@ -7,7 +7,6 @@ from CveXplore.common.config import Configuration from CveXplore.core.logging.formatters.task_formatter import TaskFormatter from CveXplore.core.logging.handlers.gelf_handler import GelfUDPHandler -from CveXplore.core.logging.handlers.syslog_handler import FullSysLogHandler CRITICAL = 50 FATAL = CRITICAL @@ -77,6 +76,11 @@ def __init__(self, name, level=logging.NOTSET): ), ) else: + # Import syslog_handler only if configured (for Windows compatibility) + from CveXplore.core.logging.handlers.syslog_handler import ( + FullSysLogHandler, + ) + syslog = FullSysLogHandler( address=(syslog_server, syslog_port), facility=FullSysLogHandler.LOG_LOCAL0,