33import sys
44import argparse
55from os import environ
6- from os .path import join , exists
6+ from os .path import join , exists , isdir
77import json
88
99# make sure O2DPG + O2 is loaded
1414 sys .exit (1 )
1515
1616
17+ def get_config (path = None ):
18+ default_path = join (O2DPG_ROOT , "MC" , "config" , "analysis_testing" , "json" , "analyses_config.json" )
19+ if not path :
20+ return default_path
21+
22+ if isdir (path ):
23+ # assume to look for analyses_config.json in this directory
24+ path = join (path , "analyses_config.json" )
25+
26+ if not exists (path ):
27+ print (f"WARNING: Cannot locate config for AnalysisQC at custom path { path } . USe default at { default_path } " )
28+ return default_path
29+
30+ with open (path , "r" ) as f :
31+ return json .load (f )["analyses" ]
32+
33+
1734def modify (args ):
1835 """
1936 modify and create a new config
2037 """
2138
22- analyses = None
23- with open (args .config , "r" ) as f :
24- analyses = json .load (f )["analyses" ]
39+ analyses = get_config (args .config )
2540
2641 for ana in analyses :
2742 if args .disable_tasks and ana ["name" ] in args .disable_tasks :
@@ -51,9 +66,7 @@ def print_status(enabled):
5166 return
5267 print ("DISABLED" )
5368
54- analyses = None
55- with open (args .config , "r" ) as f :
56- analyses = json .load (f )["analyses" ]
69+ analyses = get_config (args .config )
5770
5871 for ana in analyses :
5972 if ana ["name" ] == args .task :
@@ -80,9 +93,7 @@ def show_tasks(args):
8093 args .enabled = True
8194 args .disabled = True
8295
83- analyses = None
84- with open (args .config , "r" ) as f :
85- analyses = json .load (f )["analyses" ]
96+ analyses = get_config (args .config )
8697
8798 for ana in analyses :
8899 if (args .enabled and ana ["enabled" ]) or (args .disabled and not ana ["enabled" ]):
@@ -92,9 +103,12 @@ def show_tasks(args):
92103
93104
94105def validate_output (args ):
95- analyses = None
96- with open (args .config , "r" ) as f :
97- analyses = json .load (f )["analyses" ]
106+
107+ if not args .config :
108+ # first see if config is not explicitly given, then use the directory where the analyses to check are located
109+ args .config = args .directory
110+
111+ analyses = get_config (args .config )
98112
99113 # global return code
100114 ret = 0
@@ -105,11 +119,10 @@ def validate_output(args):
105119 analysis_name = ana ["name" ]
106120
107121 if args .tasks :
108- if analysis_name in args .tasks :
109- # tasks were specified explicitly, make sure to take them into account at all costs
110- include_disabled = True
111- else :
122+ if analysis_name not in args .tasks :
112123 continue
124+ # tasks were specified explicitly, make sure to take them into account at all costs
125+ include_disabled = True
113126
114127 if not ana ["enabled" ] and not include_disabled :
115128 # continue if disabled and not including those
@@ -160,7 +173,7 @@ def main():
160173 sub_parsers = parser .add_subparsers (dest = "command" )
161174
162175 config_parser = argparse .ArgumentParser (add_help = False )
163- config_parser .add_argument ("-c" , "--config" , help = "input configuration to modify" , default = join ( O2DPG_ROOT , "MC" , "config" , "analysis_testing" , "json" , "analyses_config.json" ) )
176+ config_parser .add_argument ("-c" , "--config" , help = "input configuration to modify" )
164177
165178 # modify config
166179 modify_parser = sub_parsers .add_parser ("modify" , parents = [config_parser ])
0 commit comments