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,75 @@ 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 (
43+ cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
44+ ) -> dict :
12245 """
12346 :param str cname: the target cname to get the feature dict for
12447 :param str gardenlinux_root: path of garden linux src root
12548 :return: dict with list of features for a given cname, split into platform, element and flag
12649
12750 """
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 )
51+
52+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
13253 features = __reverse_sort_nodes (graph )
13354 features_by_type = dict ()
55+
13456 for type in ["platform" , "element" , "flag" ]:
13557 features_by_type [type ] = [
13658 feature
13759 for feature in features
13860 if __get_node_type (graph .nodes [feature ]) == type
13961 ]
140- return features_by_type
14162
63+ return features_by_type
14264
143- def get_features_list (cname : str , gardenlinux_root : str ) -> list :
65+ def get_features_graph (
66+ cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
67+ ) -> networkx .graph :
14468 """
14569 :param str cname: the target cname to get the feature dict for
14670 :param str gardenlinux_root: path of garden linux src root
14771 :return: list of features for a given cname
14872
14973 """
150- feature_base_dir = f"{ gardenlinux_root } /features"
74+
75+ feature_base_dir = f"{ gardenlinux_root } /{ feature_dir_name } "
15176 input_features = __reverse_cname_base (cname )
15277 feature_graph = read_feature_files (feature_base_dir )
15378 graph = filter_graph (feature_graph , input_features )
79+
80+ return graph
81+
82+
83+ def get_features_list (
84+ cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
85+ ) -> list :
86+ """
87+ :param str cname: the target cname to get the feature dict for
88+ :param str gardenlinux_root: path of garden linux src root
89+ :return: list of features for a given cname
90+
91+ """
92+
93+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
15494 features = __reverse_sort_nodes (graph )
95+
15596 return features
15697
15798
158- def get_features (cname : str , gardenlinux_root : str ) -> str :
99+ def get_features (
100+ cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
101+ ) -> str :
159102 """
160103 :param str cname: the target cname to get the feature set for
161104 :param str gardenlinux_root: path of garden linux src root
162105 :return: a comma separated string with the expanded feature set for the cname
163106 """
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 )
107+
108+ graph = get_features_graph (cname , gardenlinux_root , feature_dir_name )
168109 features = __reverse_sort_nodes (graph )
110+
169111 return "," .join (features )
170112
171113
@@ -458,7 +400,7 @@ def __sort_key(graph, node):
458400 return f"{ prefix } -{ node } "
459401
460402
461- def __sort_nodes (graph ):
403+ def sort_nodes (graph ):
462404 def key_function (node ):
463405 return __sort_key (graph , node )
464406
@@ -473,7 +415,7 @@ def __reverse_cname_base(cname):
473415def __reverse_sort_nodes (graph ):
474416 reverse_graph = graph .reverse ()
475417 assert networkx .is_directed_acyclic_graph (reverse_graph )
476- return __sort_nodes (reverse_graph )
418+ return sort_nodes (reverse_graph )
477419
478420
479421def __get_node_type (node ):
0 commit comments