1+ from ..constants import GL_MEDIA_TYPE_LOOKUP , GL_MEDIA_TYPES
2+
13from glob import glob
2- from git .objects import commit
34import yaml
45import networkx
56import os
910
1011from pygments .filter import apply_filters
1112
12- # It is important that this list is sorted in descending length of the entries
13- GL_MEDIA_TYPES = [
14- "gcpimage.tar.gz.log" ,
15- "firecracker.tar.gz" ,
16- "platform.test.log" ,
17- "platform.test.xml" ,
18- "gcpimage.tar.gz" ,
19- "chroot.test.log" ,
20- "chroot.test.xml" ,
21- "pxe.tar.gz.log" ,
22- "root.squashfs" ,
23- "manifest.log" ,
24- "release.log" ,
25- "pxe.tar.gz" ,
26- "qcow2.log" ,
27- "test-log" ,
28- "boot.efi" ,
29- "manifest" ,
30- "vmdk.log" ,
31- "tar.log" ,
32- "uki.log" ,
33- "vmlinuz" ,
34- "release" ,
35- "vhd.log" ,
36- "ova.log" ,
37- "raw.log" ,
38- "oci.log" ,
39- "initrd" ,
40- "tar.gz" ,
41- "qcow2" ,
42- "tar" ,
43- "iso" ,
44- "oci" ,
45- "vhd" ,
46- "vmdk" ,
47- "ova" ,
48- "uki" ,
49- "raw" ,
50- ]
51-
52-
53- GL_MEDIA_TYPE_LOOKUP = {
54- "tar" : "application/io.gardenlinux.image.archive.format.tar" ,
55- "tar.gz" : "application/io.gardenlinux.image.archive.format.tar.gz" ,
56- "pxe.tar.gz" : "application/io.gardenlinux.image.archive.format.pxe.tar.gz" ,
57- "iso" : "application/io.gardenlinux.image.archive.format.iso" ,
58- "oci" : "application/io.gardenlinux.image.archive.format.oci" ,
59- "firecracker.tar.gz" : "application/io.gardenlinux.image.archive.format.firecracker.tar.gz" ,
60- "qcow2" : "application/io.gardenlinux.image.format.qcow2" ,
61- "vhd" : "application/io.gardenlinux.image.format.vhd" ,
62- "gcpimage.tar.gz" : "application/io.gardenlinux.image.format.gcpimage.tar.gz" ,
63- "vmdk" : "application/io.gardenlinux.image.format.vmdk" ,
64- "ova" : "application/io.gardenlinux.image.format.ova" ,
65- "uki" : "application/io.gardenlinux.uki" ,
66- "uki.log" : "application/io.gardenlinux.log" ,
67- "raw" : "application/io.gardenlinux.image.archive.format.raw" ,
68- "manifest.log" : "application/io.gardenlinux.log" ,
69- "release.log" : "application/io.gardenlinux.log" ,
70- "test-log" : "application/io.gardenlinux.test-log" ,
71- "manifest" : "application/io.gardenlinux.manifest" ,
72- "tar.log" : "application/io.gardenlinux.log" ,
73- "release" : "application/io.gardenlinux.release" ,
74- "raw.log" : "application/io.gardenlinux.log" ,
75- "qcow2.log" : "application/io.gardenlinux.log" ,
76- "pxe.tar.gz.log" : "application/io.gardenlinux.log" ,
77- "gcpimage.tar.gz.log" : "application/io.gardenlinux.log" ,
78- "vmdk.log" : "application/io.gardenlinux.log" ,
79- "vhd.log" : "application/io.gardenlinux.log" ,
80- "ova.log" : "application/io.gardenlinux.log" ,
81- "vmlinuz" : "application/io.gardenlinux.kernel" ,
82- "initrd" : "application/io.gardenlinux.initrd" ,
83- "root.squashfs" : "application/io.gardenlinux.squashfs" ,
84- "boot.efi" : "application/io.gardenlinux.efi" ,
85- "platform.test.log" : "application/io.gardenlinux.io.platform.test.log" ,
86- "platform.test.xml" : "application/io.gardenlinux.io.platform.test.xml" ,
87- "chroot.test.log" : "application/io.gardenlinux.io.chroot.test.log" ,
88- "chroot.test.xml" : "application/io.gardenlinux.io.chroot.test.xml" ,
89- "oci.log" : "application/io.gardenlinux.log" ,
90- }
91-
9213
9314def get_gardenlinux_commit (gardenlinux_root : str , limit : Optional [int ] = None ) -> str :
9415 """
@@ -118,54 +39,67 @@ def get_gardenlinux_commit(gardenlinux_root: str, limit: Optional[int] = None) -
11839 return commit_str
11940
12041
121- def get_features_dict (cname : str , gardenlinux_root : str ) -> dict :
42+ def get_features_dict (cname : str , gardenlinux_root : str , feature_dir_name : str = "features" ) -> dict :
12243 """
12344 :param str cname: the target cname to get the feature dict for
12445 :param str gardenlinux_root: path of garden linux src root
12546 :return: dict with list of features for a given cname, split into platform, element and flag
12647
12748 """
128- feature_base_dir = f"{ gardenlinux_root } /features"
129- input_features = __reverse_cname_base (cname )
130- feature_graph = read_feature_files (feature_base_dir )
131- graph = filter_graph (feature_graph , input_features )
49+
50+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
13251 features = __reverse_sort_nodes (graph )
13352 features_by_type = dict ()
53+
13454 for type in ["platform" , "element" , "flag" ]:
13555 features_by_type [type ] = [
13656 feature
13757 for feature in features
13858 if __get_node_type (graph .nodes [feature ]) == type
13959 ]
140- return features_by_type
14160
61+ return features_by_type
14262
143- def get_features_list (cname : str , gardenlinux_root : str ) -> list :
63+ def get_features_graph (cname : str , gardenlinux_root : str , feature_dir_name : str = "features" ) -> networkx . graph :
14464 """
14565 :param str cname: the target cname to get the feature dict for
14666 :param str gardenlinux_root: path of garden linux src root
14767 :return: list of features for a given cname
14868
14969 """
150- feature_base_dir = f"{ gardenlinux_root } /features"
70+
71+ feature_base_dir = f"{ gardenlinux_root } /{ feature_dir_name } "
15172 input_features = __reverse_cname_base (cname )
15273 feature_graph = read_feature_files (feature_base_dir )
15374 graph = filter_graph (feature_graph , input_features )
75+
76+ return graph
77+
78+
79+ def get_features_list (cname : str , gardenlinux_root : str , feature_dir_name : str = "features" ) -> list :
80+ """
81+ :param str cname: the target cname to get the feature dict for
82+ :param str gardenlinux_root: path of garden linux src root
83+ :return: list of features for a given cname
84+
85+ """
86+
87+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
15488 features = __reverse_sort_nodes (graph )
89+
15590 return features
15691
15792
158- def get_features (cname : str , gardenlinux_root : str ) -> str :
93+ def get_features (cname : str , gardenlinux_root : str , feature_dir_name : str = "features" ) -> str :
15994 """
16095 :param str cname: the target cname to get the feature set for
16196 :param str gardenlinux_root: path of garden linux src root
16297 :return: a comma separated string with the expanded feature set for the cname
16398 """
164- feature_base_dir = f"{ gardenlinux_root } /features"
165- input_features = __reverse_cname_base (cname )
166- feature_graph = read_feature_files (feature_base_dir )
167- graph = filter_graph (feature_graph , input_features )
99+
100+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
168101 features = __reverse_sort_nodes (graph )
102+
169103 return "," .join (features )
170104
171105
@@ -458,7 +392,7 @@ def __sort_key(graph, node):
458392 return f"{ prefix } -{ node } "
459393
460394
461- def __sort_nodes (graph ):
395+ def sort_nodes (graph ):
462396 def key_function (node ):
463397 return __sort_key (graph , node )
464398
@@ -473,7 +407,7 @@ def __reverse_cname_base(cname):
473407def __reverse_sort_nodes (graph ):
474408 reverse_graph = graph .reverse ()
475409 assert networkx .is_directed_acyclic_graph (reverse_graph )
476- return __sort_nodes (reverse_graph )
410+ return sort_nodes (reverse_graph )
477411
478412
479413def __get_node_type (node ):
0 commit comments