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