88from configparser import UNNAMED_SECTION , ConfigParser
99from os import PathLike , environ
1010from pathlib import Path
11- from typing import List , Optional
11+ from typing import Optional
1212
1313from ..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"""
273316ID={ GL_RELEASE_ID }
@@ -283,24 +326,14 @@ def release_metadata_string(self) -> str:
283326GARDENLINUX_FEATURES_PLATFORM="{ platform } "
284327GARDENLINUX_FEATURES_ELEMENTS="{ elements } "
285328GARDENLINUX_FEATURES_FLAGS="{ flags } "
329+ GARDENLINUX_PLATFORM_VARIANT="{ platform_variant } "
286330GARDENLINUX_VERSION="{ self .version } "
287331GARDENLINUX_COMMIT_ID="{ self .commit_id } "
288332GARDENLINUX_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 """
@@ -360,12 +393,18 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
360393 )
361394
362395 loaded_cname_instance = CName (
363- release_config .get (UNNAMED_SECTION , "GARDENLINUX_CNAME" )
396+ release_config .get (UNNAMED_SECTION , "GARDENLINUX_CNAME" ). strip ( " \" '" )
364397 )
365398
366- commit_id = release_config .get (UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID" )
367- commit_hash = release_config .get (UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID_LONG" )
368- version = release_config .get (UNNAMED_SECTION , "GARDENLINUX_VERSION" )
399+ commit_id = release_config .get (UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID" ).strip (
400+ "\" '"
401+ )
402+ commit_hash = release_config .get (
403+ UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID_LONG"
404+ ).strip ("\" '" )
405+ version = release_config .get (UNNAMED_SECTION , "GARDENLINUX_VERSION" ).strip (
406+ "\" '"
407+ )
369408
370409 if (
371410 loaded_cname_instance .flavor != self .flavor
@@ -386,19 +425,28 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
386425
387426 self ._feature_set_cached = release_config .get (
388427 UNNAMED_SECTION , "GARDENLINUX_FEATURES"
389- )
428+ ). strip ( " \" '" )
390429
391- self ._feature_elements_cached = release_config .get (
392- UNNAMED_SECTION , "GARDENLINUX_FEATURES_ELEMENTS"
393- ).split ("," )
430+ self ._feature_elements_cached = (
431+ release_config .get (UNNAMED_SECTION , "GARDENLINUX_FEATURES_ELEMENTS" )
432+ .strip ("\" '" )
433+ .split ("," )
434+ )
394435
395- self ._feature_flags_cached = release_config .get (
396- UNNAMED_SECTION , "GARDENLINUX_FEATURES_FLAGS"
397- ).split ("," )
436+ self ._feature_flags_cached = (
437+ release_config .get (UNNAMED_SECTION , "GARDENLINUX_FEATURES_FLAGS" )
438+ .strip ("\" '" )
439+ .split ("," )
440+ )
398441
399442 self ._feature_platform_cached = release_config .get (
400443 UNNAMED_SECTION , "GARDENLINUX_FEATURES_PLATFORM"
401- )
444+ ).strip ("\" '" )
445+
446+ if release_config .has_option (UNNAMED_SECTION , "GARDENLINUX_PLATFORM_VARIANT" ):
447+ self ._platform_variant_cached = release_config .get (
448+ UNNAMED_SECTION , "GARDENLINUX_PLATFORM_VARIANT"
449+ ).strip ("\" '" )
402450
403451 def save_to_release_file (
404452 self , release_file : PathLike | str , overwrite : Optional [bool ] = False
0 commit comments