From 790b84712ade833630490f5c849da9ed7760a914 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 7 Nov 2024 15:53:10 +0100 Subject: [PATCH] chg: [main] detect case data_subfolder using sysdiagnose.log --- src/sysdiagnose/utils/base.py | 18 ++++++++++++------ src/sysdiagnose/utils/misc.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sysdiagnose/utils/base.py b/src/sysdiagnose/utils/base.py index 51a1bdf..8ec10e5 100644 --- a/src/sysdiagnose/utils/base.py +++ b/src/sysdiagnose/utils/base.py @@ -1,11 +1,12 @@ from abc import ABC, abstractmethod -import os -import json -from pathlib import Path from datetime import datetime -import re from functools import cached_property +from pathlib import Path from sysdiagnose.utils.logger import logger +import glob +import json +import os +import re class SysdiagnoseConfig: @@ -44,8 +45,13 @@ def __init__(self, module_filename: str, config: SysdiagnoseConfig, case_id: str self.case_data_folder = config.get_case_data_folder(case_id) os.makedirs(self.case_data_folder, exist_ok=True) - case_data_folder_dirlist = os.listdir(self.case_data_folder) - self.case_data_subfolder = os.path.join(self.case_data_folder, [item for item in case_data_folder_dirlist if 'sysdiagnose_' in item][0]) + + # Search for the 'sysdiagnose.log' file and return the parent folder + log_files = glob.glob(os.path.join(self.case_data_folder, '**', 'sysdiagnose.log'), recursive=True) + if log_files: + self.case_data_subfolder = os.path.dirname(log_files[0]) + else: + self.case_data_subfolder = self.case_data_folder self.case_parsed_data_folder = config.get_case_parsed_data_folder(case_id) os.makedirs(self.case_parsed_data_folder, exist_ok=True) diff --git a/src/sysdiagnose/utils/misc.py b/src/sysdiagnose/utils/misc.py index be45102..efccdc4 100644 --- a/src/sysdiagnose/utils/misc.py +++ b/src/sysdiagnose/utils/misc.py @@ -53,7 +53,7 @@ def load_plist_string_as_json(plist_string: str) -> dict: return json_serializable(plist) -def load_plist_bytes_as_json(plist_bytes: bytes): +def load_plist_bytes_as_json(plist_bytes: bytes) -> dict: plist = nska_deserialize.deserialize_plist_from_string(plist_bytes, full_recurse_convert_nska=True, format=dict) return json_serializable(plist)