@@ -42,17 +42,14 @@ def main() -> None:
42
42
parser = argparse .ArgumentParser ()
43
43
44
44
parser .add_argument ("--arch" , dest = "arch" )
45
- parser .add_argument ("--cname" , dest = "cname" )
45
+ parser .add_argument ("--cname" , dest = "cname" , required = True )
46
46
parser .add_argument ("--commit" , dest = "commit" )
47
47
parser .add_argument ("--feature-dir" , default = "features" )
48
+ parser .add_argument ("--release-file" , dest = "release_file" )
48
49
parser .add_argument ("--default-arch" , dest = "default_arch" )
49
50
parser .add_argument ("--default-version" , dest = "default_version" )
50
51
parser .add_argument ("--version" , dest = "version" )
51
52
52
- parser .add_argument (
53
- "--features" , type = lambda arg : set ([f for f in arg .split ("," ) if f ])
54
- )
55
-
56
53
parser .add_argument (
57
54
"--ignore" ,
58
55
dest = "ignore" ,
@@ -64,9 +61,9 @@ def main() -> None:
64
61
65
62
args = parser .parse_args ()
66
63
67
- assert bool (args .features ) or bool (
68
- args .cname
69
- ), "Please provide either `--features ` or `--cname ` argument"
64
+ assert bool (args .feature_dir ) or bool (
65
+ args .release_file
66
+ ), "Please provide either `--feature_dir ` or `--release_file ` argument"
70
67
71
68
arch = args .arch
72
69
flavor = None
@@ -99,15 +96,14 @@ def main() -> None:
99
96
args .cname , arch = arch , commit_hash = commit_id_or_hash , version = version
100
97
)
101
98
99
+ if args .release_file is not None :
100
+ cname .load_from_release_file (args .release_file )
101
+
102
102
arch = cname .arch
103
103
flavor = cname .flavor
104
104
commit_id_or_hash = cname .commit_id
105
105
version = cname .version
106
106
107
- input_features = Parser .get_cname_as_feature_set (flavor )
108
- else :
109
- input_features = args .features
110
-
111
107
if arch is None or arch == "" and (args .type in ("cname" , "arch" )):
112
108
raise RuntimeError (
113
109
"Architecture could not be determined and no default architecture set"
@@ -122,53 +118,25 @@ def main() -> None:
122
118
123
119
feature_dir_name = path .basename (args .feature_dir )
124
120
125
- additional_filter_func = lambda node : node not in args .ignore
126
-
127
121
if args .type == "arch" :
128
122
print (arch )
129
- elif args .type in ("cname_base" , "cname" , "graph" ):
130
- graph = Parser (gardenlinux_root , feature_dir_name ).filter (
131
- flavor , additional_filter_func = additional_filter_func
132
- )
133
-
134
- sorted_features = Parser .sort_graph_nodes (graph )
135
- minimal_feature_set = get_minimal_feature_set (graph )
136
-
137
- sorted_minimal_features = sort_subset (minimal_feature_set , sorted_features )
138
-
139
- cname_base = get_cname_base (sorted_minimal_features )
140
-
141
- if args .type == "cname_base" :
142
- print (cname_base )
143
- elif args .type == "cname" :
144
- cname = flavor
145
-
146
- if arch is not None :
147
- cname += f"-{ arch } "
148
-
149
- if commit_id_or_hash is not None :
150
- cname += f"-{ version } -{ commit_id_or_hash [:8 ]} "
123
+ elif args .type in (
124
+ "cname_base" ,
125
+ "cname" ,
126
+ "elements" ,
127
+ "features" ,
128
+ "flags" ,
129
+ "graph" ,
130
+ "platforms" ,
131
+ ):
132
+ if args .type == "graph" or len (args .ignore ) > 1 :
133
+ features_parser = Parser (gardenlinux_root , feature_dir_name )
151
134
152
- print (cname )
153
- elif args .type == "graph" :
154
- print (graph_as_mermaid_markup (flavor , graph ))
155
- elif args .type == "features" :
156
- print (
157
- Parser (gardenlinux_root , feature_dir_name ).filter_as_string (
158
- flavor , additional_filter_func = additional_filter_func
135
+ print_output_from_features_parser (
136
+ args .type , features_parser , flavor , args .ignore
159
137
)
160
- )
161
- elif args .type in ("flags" , "elements" , "platforms" ):
162
- features_by_type = Parser (gardenlinux_root , feature_dir_name ).filter_as_dict (
163
- flavor , additional_filter_func = additional_filter_func
164
- )
165
-
166
- if args .type == "platforms" :
167
- print ("," .join (features_by_type ["platform" ]))
168
- elif args .type == "elements" :
169
- print ("," .join (features_by_type ["element" ]))
170
- elif args .type == "flags" :
171
- print ("," .join (features_by_type ["flag" ]))
138
+ else :
139
+ print_output_from_cname (args .type , cname )
172
140
elif args .type == "commit_id" :
173
141
print (commit_id_or_hash [:8 ])
174
142
elif args .type == "version" :
@@ -255,6 +223,95 @@ def graph_as_mermaid_markup(flavor: str, graph: Any) -> str:
255
223
return markup
256
224
257
225
226
+ def print_output_from_features_parser (
227
+ output_type : str , parser : Parser , flavor : str , ignores_list : set
228
+ ) -> None :
229
+ """
230
+ Prints output to stdout based on the given features parser and parameters.
231
+
232
+ :param output_type: Output type
233
+ :param parser: Features parser
234
+ :param flavor: Flavor
235
+ :param ignores_list: Features to ignore
236
+
237
+ :since: 0.11.0
238
+ """
239
+
240
+ additional_filter_func = lambda node : node not in ignores_list
241
+
242
+ if output_type == "features" :
243
+ print (
244
+ parser .filter_as_string (
245
+ flavor , additional_filter_func = additional_filter_func
246
+ )
247
+ )
248
+ elif (output_type in "platforms" , "elements" , "flags" ):
249
+ features_by_type = parser .filter_as_dict (
250
+ flavor , additional_filter_func = additional_filter_func
251
+ )
252
+
253
+ if output_type == "platforms" :
254
+ print ("," .join (features_by_type ["platform" ]))
255
+ elif output_type == "elements" :
256
+ print ("," .join (features_by_type ["element" ]))
257
+ elif output_type == "flags" :
258
+ print ("," .join (features_by_type ["flag" ]))
259
+ else :
260
+ graph = parser .filter (flavor , additional_filter_func = additional_filter_func )
261
+
262
+ sorted_features = Parser .sort_graph_nodes (graph )
263
+ minimal_feature_set = get_minimal_feature_set (graph )
264
+
265
+ sorted_minimal_features = sort_subset (minimal_feature_set , sorted_features )
266
+
267
+ cname_base = get_cname_base (sorted_minimal_features )
268
+
269
+ if output_type == "cname_base" :
270
+ print (cname_base )
271
+ elif output_type == "cname" :
272
+ cname = flavor
273
+
274
+ if arch is not None :
275
+ cname += f"-{ arch } "
276
+
277
+ if commit_id_or_hash is not None :
278
+ cname += f"-{ version } -{ commit_id_or_hash [:8 ]} "
279
+
280
+ print (cname )
281
+ if output_type == "platforms" :
282
+ print ("," .join (features_by_type ["platform" ]))
283
+ elif output_type == "elements" :
284
+ print ("," .join (features_by_type ["element" ]))
285
+ elif output_type == "flags" :
286
+ print ("," .join (features_by_type ["flag" ]))
287
+ elif output_type == "graph" :
288
+ print (graph_as_mermaid_markup (flavor , graph ))
289
+
290
+
291
+ def print_output_from_cname (output_type : str , cname_instance : CName ) -> None :
292
+ """
293
+ Prints output to stdout based on the given CName instance.
294
+
295
+ :param output_type: Output type
296
+ :param cname_instance: CName instance
297
+
298
+ :since: 0.11.0
299
+ """
300
+
301
+ if output_type == "cname_base" :
302
+ print (cname_instance .flavor )
303
+ elif output_type == "cname" :
304
+ print (cname_instance .cname )
305
+ elif output_type == "platforms" :
306
+ print (cname_instance .feature_set_platform )
307
+ elif output_type == "elements" :
308
+ print (cname_instance .feature_set_element )
309
+ elif output_type == "features" :
310
+ print (cname_instance .feature_set )
311
+ elif output_type == "flags" :
312
+ print (cname_instance .feature_set_flag )
313
+
314
+
258
315
def sort_subset (input_set : Set [str ], order_list : List [str ]) -> List [str ]:
259
316
"""
260
317
Returns items from `order_list` if given in `input_set`.
0 commit comments