@@ -38,6 +38,7 @@ def get_gardenlinux_commit(gardenlinux_root: str, limit: Optional[int] = None) -
3838 else :
3939 return commit_str
4040
41+
4142def get_features_dict (
4243 cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
4344) -> dict :
@@ -61,6 +62,7 @@ def get_features_dict(
6162
6263 return features_by_type
6364
65+
6466def get_features_graph (
6567 cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
6668) -> networkx .graph :
@@ -78,6 +80,7 @@ def get_features_graph(
7880
7981 return graph
8082
83+
8184def get_features_list (
8285 cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
8386) -> list :
@@ -93,6 +96,7 @@ def get_features_list(
9396
9497 return features
9598
99+
96100def get_features (
97101 cname : str , gardenlinux_root : str , feature_dir_name : str = "features"
98102) -> str :
@@ -107,6 +111,7 @@ def get_features(
107111
108112 return "," .join (features )
109113
114+
110115def construct_layer_metadata (
111116 filetype : str , cname : str , version : str , arch : str , commit : str
112117) -> dict :
@@ -125,6 +130,7 @@ def construct_layer_metadata(
125130 "annotations" : {"io.gardenlinux.image.layer.architecture" : arch },
126131 }
127132
133+
128134def construct_layer_metadata_from_filename (filename : str , arch : str ) -> dict :
129135 """
130136 :param str filename: filename of the blob
@@ -138,6 +144,7 @@ def construct_layer_metadata_from_filename(filename: str, arch: str) -> dict:
138144 "annotations" : {"io.gardenlinux.image.layer.architecture" : arch },
139145 }
140146
147+
141148def get_file_set_from_cname (cname : str , version : str , arch : str , gardenlinux_root : str ):
142149 """
143150 :param str cname: the target cname of the image
@@ -160,6 +167,7 @@ def get_file_set_from_cname(cname: str, version: str, arch: str, gardenlinux_roo
160167 )
161168 return file_set
162169
170+
163171def get_oci_metadata_from_fileset (fileset : list , arch : str ):
164172 """
165173 :param str arch: arch of the target image
@@ -175,6 +183,7 @@ def get_oci_metadata_from_fileset(fileset: list, arch: str):
175183
176184 return oci_layer_metadata_list
177185
186+
178187def get_oci_metadata (cname : str , version : str , arch : str , gardenlinux_root : str ):
179188 """
180189 :param str cname: the target cname of the image
@@ -197,6 +206,7 @@ def get_oci_metadata(cname: str, version: str, arch: str, gardenlinux_root: str)
197206
198207 return oci_layer_metadata_list
199208
209+
200210def lookup_media_type_for_filetype (filetype : str ) -> str :
201211 """
202212 :param str filetype: filetype of the target layer
@@ -209,6 +219,7 @@ def lookup_media_type_for_filetype(filetype: str) -> str:
209219 f"media type for { filetype } is not defined. You may want to add the definition to parse_features_lib"
210220 )
211221
222+
212223def lookup_media_type_for_file (filename : str ) -> str :
213224 """
214225 :param str filename: filename of the target layer
@@ -222,6 +233,7 @@ def lookup_media_type_for_file(filename: str) -> str:
222233 f"media type for { filename } is not defined. You may want to add the definition to parse_features_lib"
223234 )
224235
236+
225237def deduce_feature_name (feature_dir : str ):
226238 """
227239 :param str feature_dir: Directory of single Feature
@@ -232,20 +244,23 @@ def deduce_feature_name(feature_dir: str):
232244 raise ValueError ("Expected name from parse_feature_yaml function to be set" )
233245 return parsed ["name" ]
234246
247+
235248def deduce_archive_filetypes (feature_dir ):
236249 """
237250 :param str feature_dir: Directory of single Feature
238251 :return: str list of filetype for archive
239252 """
240253 return deduce_filetypes_from_string (feature_dir , "image" )
241254
255+
242256def deduce_image_filetypes (feature_dir ):
243257 """
244258 :param str feature_dir: Directory of single Feature
245259 :return: str list of filetype for image
246260 """
247261 return deduce_filetypes_from_string (feature_dir , "convert" )
248262
263+
249264def deduce_filetypes (feature_dir ):
250265 """
251266 :param str feature_dir: Directory of single Feature
@@ -260,6 +275,7 @@ def deduce_filetypes(feature_dir):
260275 image_file_types .extend (archive_file_types )
261276 return image_file_types
262277
278+
263279def deduce_filetypes_from_string (feature_dir : str , script_base_name : str ):
264280 """
265281 Garden Linux features can optionally have an image.<filetype> or convert.<filetype> script,
@@ -283,6 +299,7 @@ def deduce_filetypes_from_string(feature_dir: str, script_base_name: str):
283299
284300 return sorted (result )
285301
302+
286303def read_feature_files (feature_dir ):
287304 """
288305 Legacy function copied from gardenlinux/builder
@@ -312,6 +329,7 @@ def read_feature_files(feature_dir):
312329 raise ValueError ("Graph is not directed acyclic graph" )
313330 return feature_graph
314331
332+
315333def parse_feature_yaml (feature_yaml_file : str ):
316334 """
317335 Legacy function copied from gardenlinux/builder
@@ -328,9 +346,11 @@ def parse_feature_yaml(feature_yaml_file: str):
328346 content = yaml .safe_load (f )
329347 return {"name" : name , "content" : content }
330348
349+
331350def __get_node_features (node ):
332351 return node .get ("content" , {}).get ("features" , {})
333352
353+
334354def filter_graph (feature_graph , feature_set , ignore_excludes = False ):
335355 filter_set = set (feature_graph .nodes ())
336356
@@ -369,29 +389,35 @@ def filter_func(node):
369389 raise ValueError ("Including explicitly excluded feature" )
370390 return graph
371391
392+
372393def sort_set (input_set , order_list ):
373394 return [item for item in order_list if item in input_set ]
374395
396+
375397def __sort_key (graph , node ):
376398 prefix_map = {"platform" : "0" , "element" : "1" , "flag" : "2" }
377399 node_type = __get_node_type (graph .nodes .get (node , {}))
378400 prefix = prefix_map [node_type ]
379401 return f"{ prefix } -{ node } "
380402
403+
381404def sort_nodes (graph ):
382405 def key_function (node ):
383406 return __sort_key (graph , node )
384407
385408 return list (networkx .lexicographical_topological_sort (graph , key = key_function ))
386409
410+
387411def __reverse_cname_base (cname ):
388412 cname = cname .replace ("_" , "-_" )
389413 return set (cname .split ("-" ))
390414
415+
391416def __reverse_sort_nodes (graph ):
392417 reverse_graph = graph .reverse ()
393418 assert networkx .is_directed_acyclic_graph (reverse_graph )
394419 return sort_nodes (reverse_graph )
395420
421+
396422def __get_node_type (node ):
397423 return node .get ("content" , {}).get ("type" )
0 commit comments