3434import hashlib
3535import json
3636import os
37+ import re
3738import subprocess as sp # nosec B404
3839import sys
3940
@@ -81,11 +82,11 @@ def load_workflows_from_json():
8182 return db_wf
8283
8384
84- def format_table_name (description : str , subspec : int ):
85- """Format table description name, including potential versions."""
86- if not subspec :
87- return description
88- return f"{ description } _ { subspec :03d } "
85+ def format_table_name (description : str , subspec : int , origin : str ):
86+ """Format table description name, including origin and potential versions."""
87+ if subspec > 0 :
88+ description += f"_ { subspec :03d } "
89+ return f"{ origin } / { description } "
8990
9091
9192def get_devices (specs_wf : dict ):
@@ -101,7 +102,9 @@ def get_inputs(specs_wf: dict, device=""):
101102 if device and dev ["name" ] != device :
102103 continue
103104 list_inputs += [
104- format_table_name (i ["description" ], i ["subspec" ]) for i in dev ["inputs" ] if i ["origin" ] == "AOD"
105+ format_table_name (i ["description" ], i ["subspec" ], i ["origin" ])
106+ for i in dev ["inputs" ]
107+ if i ["origin" ].startswith (("AOD" , "EMB" ))
105108 ]
106109 return list (dict .fromkeys (list_inputs )) # Remove duplicities
107110
@@ -115,7 +118,9 @@ def get_outputs(specs_wf: dict, device=""):
115118 if device and dev ["name" ] != device :
116119 continue
117120 list_outputs += [
118- format_table_name (i ["description" ], i ["subspec" ]) for i in dev ["outputs" ] if i ["origin" ] == "AOD"
121+ format_table_name (i ["description" ], i ["subspec" ], i ["origin" ])
122+ for i in dev ["outputs" ]
123+ if i ["origin" ].startswith (("AOD" , "EMB" ))
119124 ]
120125 return list (dict .fromkeys (list_outputs )) # Remove duplicities
121126
@@ -229,7 +234,7 @@ def get_tree_for_table(tab: str, dic_wf_all: dict, dic_wf_tree=None, case_sensit
229234 for p in producers :
230235 get_tree_for_workflow (p , dic_wf_all , dic_wf_tree , case_sensitive , 0 , levels_max , reverse )
231236 else :
232- print (f' No { " consumers" if reverse else " producers" } found' )
237+ print (f" No { ' consumers' if reverse else ' producers' } found" )
233238 return dic_wf_tree
234239
235240
@@ -272,7 +277,7 @@ def main():
272277 dest = "exclude" ,
273278 type = str ,
274279 nargs = "+" ,
275- help = "tables and workflows to exclude" ,
280+ help = "name patterns of tables and workflows to exclude" ,
276281 )
277282 parser .add_argument (
278283 "-l" ,
@@ -299,7 +304,7 @@ def main():
299304 dic_wf_all_simple = {}
300305 for wf , dic_wf in dic_wf_all_full .items ():
301306 # Skip excluded workflows
302- if list_exclude and wf in list_exclude :
307+ if list_exclude and any ( re . search ( pattern , wf ) for pattern in list_exclude ) :
303308 continue
304309 dic_wf_all_simple [wf ] = {}
305310 list_dev = get_devices (dic_wf )
@@ -309,8 +314,8 @@ def main():
309314 list_outputs = get_outputs (dic_wf , dev )
310315 # Skip excluded tables
311316 if list_exclude :
312- list_inputs = [i for i in list_inputs if i not in list_exclude ]
313- list_outputs = [o for o in list_outputs if o not in list_exclude ]
317+ list_inputs = [i for i in list_inputs if not any ( re . search ( pattern , i ) for pattern in list_exclude ) ]
318+ list_outputs = [o for o in list_outputs if not any ( re . search ( pattern , o ) for pattern in list_exclude ) ]
314319 dic_wf_all_simple [wf ][dev ]["inputs" ] = list_inputs
315320 dic_wf_all_simple [wf ][dev ]["outputs" ] = list_outputs
316321 # print_workflows(dic_wf_all_simple)
@@ -323,9 +328,11 @@ def main():
323328 for t , reverse in zip ((tables , tables_rev ), (False , True )):
324329 if t :
325330 for table in t :
326- print (f"\n Table: { table } \n " )
327331 if not table :
328332 msg_fatal ("Bad table" )
333+ if "/" not in table :
334+ table = "AOD/" + table
335+ print (f"\n Table: { table } \n " )
329336 # producers = get_table_producers(table, dic_wf_all_simple, case_sensitive)
330337 # if not producers:
331338 # print("No producers found")
@@ -389,12 +396,12 @@ def main():
389396 inputs = get_workflow_inputs (wf , dic_deps )
390397 outputs = get_workflow_outputs (wf , dic_deps )
391398 list_tables += inputs + outputs
392- nodes_in = " " .join (inputs )
393- nodes_out = " " .join (outputs )
399+ nodes_in = " " .join (inputs ). replace ( "/" , "_" )
400+ nodes_out = " " .join (outputs ). replace ( "/" , "_" )
394401 dot_deps += f" {{{ nodes_in } }} -> { node_wf } -> {{{ nodes_out } }}\n "
395402 list_tables = list (dict .fromkeys (list_tables )) # Remove duplicities
396403 for table in list_tables :
397- dot_tables += f" { table } \n "
404+ dot_tables += f' { table . replace ( "/" , "_" ) } [label=" { table } "] \n '
398405 dot_tables += " }\n "
399406 dot_workflows += " }\n "
400407 dot += dot_workflows + dot_tables + dot_deps
0 commit comments