Skip to content

Commit

Permalink
chg: add list all
Browse files Browse the repository at this point in the history
  • Loading branch information
cvandeplas committed Jun 5, 2024
1 parent 0319af7 commit 551768a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}/"
},
{
Expand Down
12 changes: 10 additions & 2 deletions analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""sysdiagnose analyse.
Usage:
analyse.py list (cases|analysers)
analyse.py list (cases|analysers|all)
analyse.py analyse <analyser> <case_number>
analyse.py allanalysers <case_number>
analyse.py (-h | --help)
Expand Down Expand Up @@ -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 = []
Expand All @@ -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):
Expand All @@ -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('..')
Expand All @@ -84,6 +87,7 @@ def allanalysers(caseid):
analyse(analyser[:-3], caseid)
except: # noqa: E722
continue
os.chdir(prev_folder)
return 0

# --------------------------------------------------------------------------- #
Expand All @@ -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['<case_number>'].isdigit():
analyse(arguments['<analyser>'], arguments['<case_number>'])
Expand Down
2 changes: 2 additions & 0 deletions initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)


"""
Expand Down
14 changes: 11 additions & 3 deletions parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""sysdiagnose parse.
Usage:
parsing.py list (cases|parsers)
parsing.py list (cases|parsers|all)
parsing.py parse <parser> <case_number>
parsing.py allparsers <case_number>
parsing.py (-h | --help)
Expand All @@ -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)
Expand All @@ -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 = []
Expand All @@ -77,6 +78,7 @@ def list_parsers(folder):
headers = ['Parser Name', 'Parser Description']

print(tabulate(lines, headers=headers))
os.chdir(prev_folder)


"""
Expand Down Expand Up @@ -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('..')
Expand All @@ -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


Expand All @@ -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['<case_number>'].isdigit():
parse(arguments['<parser>'], arguments['<case_number>'])
Expand Down

0 comments on commit 551768a

Please sign in to comment.