3
3
'''
4
4
Create a tree chart with all the manifest includes
5
5
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)
6
8
'''
7
9
10
+ import os
8
11
import sys
9
12
import yaml
10
- import os
11
13
from anytree import Node , RenderTree
12
14
13
- def collect_included_files (filename , parent ):
15
+
16
+ def collect_included_files (filename , parent , prefix ):
14
17
node = None
18
+ if prefix :
19
+ node = Node ("(" + prefix + ") " + filename , parent )
20
+ else :
21
+ node = Node (filename , parent )
15
22
16
23
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
23
27
24
28
with open (filename , 'r' ) as file :
25
29
try :
26
30
data = yaml .safe_load (file )
27
31
if data is None :
28
32
return
29
33
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 )
40
50
except yaml .YAMLError as e :
41
51
print (f"Error parsing YAML file '{ filename } ': { e } " )
42
52
sys .exit (1 )
43
53
except Exception as e :
44
54
print (f"Error: { e } " )
45
55
sys .exit (1 )
46
56
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
+
47
70
if __name__ == "__main__" :
48
71
if len (sys .argv ) != 2 :
49
72
print ("Usage: python manifest_graph <yaml_file>" )
@@ -54,7 +77,7 @@ if __name__ == "__main__":
54
77
print (f"Error: File '{ yaml_file } ' not found." )
55
78
sys .exit (1 )
56
79
57
- root = collect_included_files (yaml_file , None )
80
+ root = collect_included_files (yaml_file , None , None )
58
81
59
82
for pre , _ , node in RenderTree (root ):
60
- print ("%s%s" % (pre , node .name ))
83
+ print ("%s%s" % (pre , node .name ))
0 commit comments