|
10 | 10 | from os import PathLike |
11 | 11 | import re |
12 | 12 |
|
13 | | -from ..constants import ARCHS |
| 13 | +from ..constants import ( |
| 14 | + ARCHS, |
| 15 | + GL_BUG_REPORT_URL, |
| 16 | + GL_COMMIT_SPECIAL_VALUES, |
| 17 | + GL_DISTRIBUTION_NAME, |
| 18 | + GL_HOME_URL, |
| 19 | + GL_RELEASE_ID, |
| 20 | + GL_SUPPORT_URL, |
| 21 | +) |
14 | 22 |
|
15 | 23 | from .parser import Parser |
16 | 24 |
|
@@ -87,7 +95,7 @@ def __init__(self, cname, arch=None, commit_hash=None, version=None): |
87 | 95 | if commit_id_or_hash is not None: |
88 | 96 | self._commit_id = commit_id_or_hash[:8] |
89 | 97 |
|
90 | | - if len(commit_id_or_hash) == 40: # sha1 hex |
| 98 | + if len(commit_id_or_hash) == 40: # sha1 hex |
91 | 99 | self._commit_hash = commit_id_or_hash |
92 | 100 |
|
93 | 101 | @property |
@@ -129,7 +137,9 @@ def commit_hash(self) -> str: |
129 | 137 | """ |
130 | 138 |
|
131 | 139 | if self._commit_hash is None: |
132 | | - raise RuntimeError("GardenLinux canonical name given does not contain the commit hash") |
| 140 | + raise RuntimeError( |
| 141 | + "GardenLinux canonical name given does not contain the commit hash" |
| 142 | + ) |
133 | 143 |
|
134 | 144 | return self._commit_hash |
135 | 145 |
|
@@ -183,6 +193,42 @@ def feature_set(self) -> str: |
183 | 193 |
|
184 | 194 | return Parser().filter_as_string(self.flavor) |
185 | 195 |
|
| 196 | + @property |
| 197 | + def metadata_string(self) -> str: |
| 198 | + """ |
| 199 | + Returns the metadata describing the given CName instance. |
| 200 | +
|
| 201 | + :return: (str) Metadata describing the given CName instance |
| 202 | + :since: 0.9.2 |
| 203 | + """ |
| 204 | + |
| 205 | + features = Parser().filter_as_dict(self.flavor) |
| 206 | + |
| 207 | + elements = ",".join(features["element"]) |
| 208 | + flags = ",".join(features["flag"]) |
| 209 | + platforms = ",".join(features["platform"]) |
| 210 | + |
| 211 | + metadata = f""" |
| 212 | +ID={GL_RELEASE_ID} |
| 213 | +NAME="{GL_DISTRIBUTION_NAME}" |
| 214 | +PRETTY_NAME="{GL_DISTRIBUTION_NAME} {self.version}" |
| 215 | +IMAGE_VERSION={self.version} |
| 216 | +VARIANT_ID="{self.flavor}-{self.arch}" |
| 217 | +HOME_URL="{GL_HOME_URL}" |
| 218 | +SUPPORT_URL="{GL_SUPPORT_URL}" |
| 219 | +BUG_REPORT_URL="{GL_BUG_REPORT_URL}" |
| 220 | +GARDENLINUX_CNAME="{self.cname}" |
| 221 | +GARDENLINUX_FEATURES="{self.feature_set}" |
| 222 | +GARDENLINUX_FEATURES_PLATFORMS="{platforms}" |
| 223 | +GARDENLINUX_FEATURES_ELEMENTS="{elements}" |
| 224 | +GARDENLINUX_FEATURES_FLAGS="{flags}" |
| 225 | +GARDENLINUX_VERSION="{self.version}" |
| 226 | +GARDENLINUX_COMMIT_ID="{self.commit_id}" |
| 227 | +GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}" |
| 228 | + """.strip() |
| 229 | + |
| 230 | + return metadata |
| 231 | + |
186 | 232 | @property |
187 | 233 | def platform(self) -> str: |
188 | 234 | """ |
@@ -317,30 +363,5 @@ def save_to_metadata_file( |
317 | 363 | f"Refused to overwrite existing metadata file: {metadata_file}" |
318 | 364 | ) |
319 | 365 |
|
320 | | - features = Parser().filter_as_dict(self.flavor) |
321 | | - |
322 | | - elements = ",".join(features["element"]) |
323 | | - flags = ",".join(features["flag"]) |
324 | | - platforms = ",".join(features["platform"]) |
325 | | - |
326 | | - metadata = f""" |
327 | | -ID=gardenlinux |
328 | | -NAME="Garden Linux" |
329 | | -PRETTY_NAME="Garden Linux {self.version}" |
330 | | -IMAGE_VERSION={self.version} |
331 | | -VARIANT_ID="{self.flavor}-{self.arch}" |
332 | | -HOME_URL="https://gardenlinux.io" |
333 | | -SUPPORT_URL="https://github.com/gardenlinux/gardenlinux" |
334 | | -BUG_REPORT_URL="https://github.com/gardenlinux/gardenlinux/issues" |
335 | | -GARDENLINUX_CNAME="{self.cname}" |
336 | | -GARDENLINUX_FEATURES="{self.feature_set}" |
337 | | -GARDENLINUX_FEATURES_PLATFORMS="{platforms}" |
338 | | -GARDENLINUX_FEATURES_ELEMENTS="{elements}" |
339 | | -GARDENLINUX_FEATURES_FLAGS="{flags}" |
340 | | -GARDENLINUX_VERSION="{self.version}" |
341 | | -GARDENLINUX_COMMIT_ID="{self.commit_id}" |
342 | | -GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}" |
343 | | - """.strip() |
344 | | - |
345 | 366 | with metadata_file.open("w") as fp: |
346 | | - fp.write(metadata) |
| 367 | + fp.write(self.metadata_string) |
0 commit comments