Skip to content

Commit 5ed0559

Browse files
committed
Reflect changes that metadata is based on the OS release metadata
Signed-off-by: Tobias Wolf <[email protected]>
1 parent d2039f3 commit 5ed0559

File tree

7 files changed

+336
-138
lines changed

7 files changed

+336
-138
lines changed

src/gardenlinux/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,7 @@
159159

160160
S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"
161161

162-
GLVD_BASE_URL = "https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1"
162+
GLVD_BASE_URL = (
163+
"https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1"
164+
)
163165
GL_DEB_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"

src/gardenlinux/features/__main__.py

Lines changed: 112 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ def main() -> None:
4242
parser = argparse.ArgumentParser()
4343

4444
parser.add_argument("--arch", dest="arch")
45-
parser.add_argument("--cname", dest="cname")
45+
parser.add_argument("--cname", dest="cname", required=True)
4646
parser.add_argument("--commit", dest="commit")
4747
parser.add_argument("--feature-dir", default="features")
48+
parser.add_argument("--release-file", dest="release_file")
4849
parser.add_argument("--default-arch", dest="default_arch")
4950
parser.add_argument("--default-version", dest="default_version")
5051
parser.add_argument("--version", dest="version")
5152

52-
parser.add_argument(
53-
"--features", type=lambda arg: set([f for f in arg.split(",") if f])
54-
)
55-
5653
parser.add_argument(
5754
"--ignore",
5855
dest="ignore",
@@ -64,9 +61,9 @@ def main() -> None:
6461

6562
args = parser.parse_args()
6663

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"
7067

7168
arch = args.arch
7269
flavor = None
@@ -99,15 +96,14 @@ def main() -> None:
9996
args.cname, arch=arch, commit_hash=commit_id_or_hash, version=version
10097
)
10198

99+
if args.release_file is not None:
100+
cname.load_from_release_file(args.release_file)
101+
102102
arch = cname.arch
103103
flavor = cname.flavor
104104
commit_id_or_hash = cname.commit_id
105105
version = cname.version
106106

107-
input_features = Parser.get_cname_as_feature_set(flavor)
108-
else:
109-
input_features = args.features
110-
111107
if arch is None or arch == "" and (args.type in ("cname", "arch")):
112108
raise RuntimeError(
113109
"Architecture could not be determined and no default architecture set"
@@ -122,53 +118,25 @@ def main() -> None:
122118

123119
feature_dir_name = path.basename(args.feature_dir)
124120

125-
additional_filter_func = lambda node: node not in args.ignore
126-
127121
if args.type == "arch":
128122
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)
151134

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
159137
)
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)
172140
elif args.type == "commit_id":
173141
print(commit_id_or_hash[:8])
174142
elif args.type == "version":
@@ -255,6 +223,95 @@ def graph_as_mermaid_markup(flavor: str, graph: Any) -> str:
255223
return markup
256224

257225

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+
258315
def sort_subset(input_set: Set[str], order_list: List[str]) -> List[str]:
259316
"""
260317
Returns items from `order_list` if given in `input_set`.

0 commit comments

Comments
 (0)