Skip to content

Commit fe8eea8

Browse files
committed
Add support for the GardenLinux platform variant if defined
Signed-off-by: Tobias Wolf <[email protected]> On-behalf-of: SAP <[email protected]>
1 parent cc4eb5b commit fe8eea8

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

src/gardenlinux/features/cname.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from configparser import UNNAMED_SECTION, ConfigParser
99
from os import PathLike, environ
1010
from pathlib import Path
11-
from typing import List, Optional
11+
from typing import Optional
1212

1313
from ..constants import (
1414
ARCHS,
@@ -53,6 +53,7 @@ def __init__(self, cname, arch=None, commit_hash=None, version=None):
5353
self._feature_flags_cached = None
5454
self._feature_platform_cached = None
5555
self._feature_set_cached = None
56+
self._platform_variant_cached = None
5657

5758
self._flag_multiple_platforms = bool(
5859
environ.get("GL_ALLOW_FRANKENSTEIN", False)
@@ -250,6 +251,44 @@ def feature_set_platform(self) -> str:
250251
"Only one platform is supported"
251252
return platforms[0]
252253

254+
@property
255+
def platform(self) -> str:
256+
"""
257+
Returns the feature set of type "platform" for the cname parsed.
258+
259+
:return: (str) Feature set platforms
260+
:since: 0.7.0
261+
"""
262+
263+
return self.feature_set_platform
264+
265+
@property
266+
def platform_variant(self) -> Optional[str]:
267+
"""
268+
Returns the platform variant for the cname parsed.
269+
270+
:return: (str) Platform variant
271+
:since: 1.0.0
272+
"""
273+
274+
if self._platform_variant_cached is not None:
275+
return self._platform_variant_cached
276+
277+
# @TODO: Platform variant is set by GardenLinux features to the release file. If not read or cached it is currently invisible for this library.
278+
return None
279+
280+
@platform_variant.setter
281+
def platform_variant(self, variant: str) -> None:
282+
"""
283+
Sets the the platform variant
284+
285+
:param variant: Platform variant
286+
287+
:since: 1.0.0
288+
"""
289+
290+
self._platform_variant_cached = variant
291+
253292
@property
254293
def release_metadata_string(self) -> str:
255294
"""
@@ -268,6 +307,10 @@ def release_metadata_string(self) -> str:
268307
elements = ",".join(features["element"])
269308
flags = ",".join(features["flag"])
270309
platform = ",".join(features["platform"])
310+
platform_variant = self.platform_variant
311+
312+
if platform_variant is None:
313+
platform_variant = ""
271314

272315
metadata = f"""
273316
ID={GL_RELEASE_ID}
@@ -283,24 +326,14 @@ def release_metadata_string(self) -> str:
283326
GARDENLINUX_FEATURES_PLATFORM="{platform}"
284327
GARDENLINUX_FEATURES_ELEMENTS="{elements}"
285328
GARDENLINUX_FEATURES_FLAGS="{flags}"
329+
GARDENLINUX_PLATFORM_VARIANT="{platform_variant}"
286330
GARDENLINUX_VERSION="{self.version}"
287331
GARDENLINUX_COMMIT_ID="{self.commit_id}"
288332
GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}"
289333
""".strip()
290334

291335
return metadata
292336

293-
@property
294-
def platform(self) -> str:
295-
"""
296-
Returns the feature set of type "platform" for the cname parsed.
297-
298-
:return: (str) Feature set platforms
299-
:since: 0.7.0
300-
"""
301-
302-
return self.feature_set_platform
303-
304337
@property
305338
def version(self) -> Optional[str]:
306339
"""
@@ -400,6 +433,11 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
400433
UNNAMED_SECTION, "GARDENLINUX_FEATURES_PLATFORM"
401434
)
402435

436+
if release_config.has_option(UNNAMED_SECTION, "GARDENLINUX_PLATFORM_VARIANT"):
437+
self._platform_variant_cached = release_config.get(
438+
UNNAMED_SECTION, "GARDENLINUX_PLATFORM_VARIANT"
439+
)
440+
403441
def save_to_release_file(
404442
self, release_file: PathLike | str, overwrite: Optional[bool] = False
405443
) -> None:

0 commit comments

Comments
 (0)