From 551768ad0b2694761d38c3c1a723a957dd65149d Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Wed, 5 Jun 2024 10:54:39 +0200 Subject: [PATCH] chg: add list all --- .vscode/launch.json | 4 ++-- analyse.py | 12 ++++++++++-- initialise.py | 2 ++ parsing.py | 14 +++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1f49597..3bc7ef2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -38,11 +38,11 @@ "cwd": "${workspaceFolder}/" }, { - "name": "Python Debugger: parsing.py list parsers", + "name": "Python Debugger: parsing.py list all", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/parsing.py", - "args": "list parsers", + "args": "list all", "cwd": "${workspaceFolder}/" }, { diff --git a/analyse.py b/analyse.py index 8f1b0a7..9ca085b 100755 --- a/analyse.py +++ b/analyse.py @@ -6,7 +6,7 @@ """sysdiagnose analyse. Usage: - analyse.py list (cases|analysers) + analyse.py list (cases|analysers|all) analyse.py analyse analyse.py allanalysers analyse.py (-h | --help) @@ -34,6 +34,7 @@ def list_analysers(folder): """ List available analysers """ + prev_folder = os.getcwd() os.chdir(folder) modules = glob.glob(os.path.join(os.path.dirname('.'), "*.py")) lines = [] @@ -52,6 +53,7 @@ def list_analysers(folder): headers = ['Analyser Name', 'Analyser Description'] print(tabulate(lines, headers=headers)) + os.chdir(prev_folder) def analyse(analyser, caseid): @@ -73,6 +75,7 @@ def analyse(analyser, caseid): def allanalysers(caseid): + prev_folder = os.getcwd() os.chdir(config.analysers_folder) modules = glob.glob(os.path.join(os.path.dirname('.'), "*.py")) os.chdir('..') @@ -84,6 +87,7 @@ def allanalysers(caseid): analyse(analyser[:-3], caseid) except: # noqa: E722 continue + os.chdir(prev_folder) return 0 # --------------------------------------------------------------------------- # @@ -99,9 +103,13 @@ def main(): arguments = docopt(__doc__, version=version_string) if arguments['list'] and arguments['cases']: - parsing.list_cases(config.cases_file) + parsing.list_cases() elif arguments['list'] and arguments['analysers']: list_analysers(config.analysers_folder) + elif arguments['list']: + list_analysers(config.analysers_folder) + print("\n") + parsing.list_cases() elif arguments['analyse']: if arguments[''].isdigit(): analyse(arguments[''], arguments['']) diff --git a/initialise.py b/initialise.py index 24ca598..729f93b 100644 --- a/initialise.py +++ b/initialise.py @@ -93,6 +93,7 @@ def init(sysdiagnose_file, force=False): # extract sysdiagnose files if config.debug: print(f"cd'ing to {new_folder}") + prev_folder = os.getcwd() os.chdir(new_folder) try: tf.extractall() @@ -142,6 +143,7 @@ def init(sysdiagnose_file, force=False): print("Sysdiagnose file has been processed") print(f"New case ID: {str(new_case['case_id'])}") + os.chdir(prev_folder) """ diff --git a/parsing.py b/parsing.py index f0ad92e..b1145dd 100755 --- a/parsing.py +++ b/parsing.py @@ -8,7 +8,7 @@ """sysdiagnose parse. Usage: - parsing.py list (cases|parsers) + parsing.py list (cases|parsers|all) parsing.py parse parsing.py allparsers parsing.py (-h | --help) @@ -35,7 +35,7 @@ """ -def list_cases(case_file): +def list_cases(): try: with open(config.cases_file, 'r') as f: cases = json.load(f) @@ -59,6 +59,7 @@ def list_cases(case_file): def list_parsers(folder): + prev_folder = os.getcwd() os.chdir(folder) modules = glob.glob(os.path.join(os.path.dirname('.'), "*.py")) lines = [] @@ -77,6 +78,7 @@ def list_parsers(folder): headers = ['Parser Name', 'Parser Description'] print(tabulate(lines, headers=headers)) + os.chdir(prev_folder) """ @@ -146,6 +148,7 @@ def parse_all(case_id): # get list of working parsers # for each parser, run and save which is working # display list of successful parses + prev_folder = os.getcwd() os.chdir(config.parsers_folder) modules = glob.glob(os.path.join(os.path.dirname('.'), "*.py")) os.chdir('..') @@ -160,6 +163,7 @@ def parse_all(case_id): print(f"Error: Problem while executing module {parser[:-3]}. Reason: {str(e)}", file=sys.stderr) print(traceback.format_exc(), file=sys.stderr) continue + os.chdir(prev_folder) return 0 @@ -179,9 +183,13 @@ def main(): # print(arguments, file=sys.stderr) if arguments['list'] and arguments['cases']: - list_cases(config.cases_file) + list_cases() elif arguments['list'] and arguments['parsers']: list_parsers(config.parsers_folder) + elif arguments['list']: + list_parsers(config.parsers_folder) + print("\n") + list_cases() elif arguments['parse']: if arguments[''].isdigit(): parse(arguments[''], arguments[''])