33'''
44 Create a tree chart with all the manifest includes
55 symlinks are displayed with a (L) prefix
6+ conditional-include values are displayed under the (condition)
7+ arch-include values are displayed under the (arch)
68'''
79
10+ import os
811import sys
912import yaml
10- import os
1113from anytree import Node , RenderTree
1214
13- def collect_included_files (filename , parent ):
15+
16+ def collect_included_files (filename , parent , prefix ):
1417 node = None
18+ if prefix :
19+ node = Node ("(" + prefix + ") " + filename , parent )
20+ else :
21+ node = Node (filename , parent )
1522
1623 if os .path .islink (filename ):
17- node = Node ("(L)" + filename , parent = parent )
18- dest = os .readlink (filename )
19- collect_included_files (dest , parent = node )
20- return node
21- else :
22- node = Node (filename , parent = parent )
24+ dest = os .readlink (filename )
25+ collect_included_files (dest , node , "L" )
26+ return node
2327
2428 with open (filename , 'r' ) as file :
2529 try :
2630 data = yaml .safe_load (file )
2731 if data is None :
2832 return
2933 include_paths = data .get ('include' )
30- if include_paths :
31- if not isinstance (include_paths , list ):
32- include_paths = [include_paths ]
33-
34- for include_path in include_paths :
35- if not os .path .isabs (include_path ):
36- include_path = os .path .join (os .path .dirname (filename ), include_path )
37- if os .path .exists (include_path ):
38- collect_included_files (include_path , parent = node )
39- return node
34+ conditional_paths = data .get ('conditional-include' )
35+ arch_paths = data .get ('arch-include' )
36+
37+ if arch_paths :
38+ for arch in ["x86_64" , "aarch64" , "s390x" , "ppc64le" ]:
39+ include = arch_paths .get (arch )
40+ if include :
41+ process_includes (filename , include , node , arch )
42+
43+ if conditional_paths :
44+ for conditional in conditional_paths :
45+ prefix = conditional .get ('if' )
46+ include = conditional .get ('include' )
47+ process_includes (filename , include , node , prefix )
48+
49+ return process_includes (filename , include_paths , node , None )
4050 except yaml .YAMLError as e :
4151 print (f"Error parsing YAML file '{ filename } ': { e } " )
4252 sys .exit (1 )
4353 except Exception as e :
4454 print (f"Error: { e } " )
4555 sys .exit (1 )
4656
57+
58+ def process_includes (filename , include_paths , parent , prefix ):
59+ if include_paths :
60+ if not isinstance (include_paths , list ):
61+ include_paths = [include_paths ]
62+
63+ for include_path in include_paths :
64+ include_path = os .path .join (os .path .dirname (filename ), include_path )
65+ if os .path .exists (include_path ):
66+ collect_included_files (include_path , parent , prefix )
67+ return parent
68+
69+
4770if __name__ == "__main__" :
4871 if len (sys .argv ) != 2 :
4972 print ("Usage: python manifest_graph <yaml_file>" )
@@ -54,7 +77,7 @@ if __name__ == "__main__":
5477 print (f"Error: File '{ yaml_file } ' not found." )
5578 sys .exit (1 )
5679
57- root = collect_included_files (yaml_file , None )
80+ root = collect_included_files (yaml_file , None , None )
5881
5982 for pre , _ , node in RenderTree (root ):
60- print ("%s%s" % (pre , node .name ))
83+ print ("%s%s" % (pre , node .name ))
0 commit comments