|
9 | 9 | import yaml |
10 | 10 | import zipfile |
11 | 11 |
|
12 | | -from . import jasyncio |
| 12 | +from . import jasyncio, origin, errors |
13 | 13 |
|
14 | 14 |
|
15 | 15 | async def execute_process(*cmd, log=None): |
@@ -234,19 +234,91 @@ def generate_user_controller_access_token(username, controller_endpoints, secret |
234 | 234 | return base64.urlsafe_b64encode(registration_string) |
235 | 235 |
|
236 | 236 |
|
237 | | -def get_local_charm_metadata(path): |
| 237 | +def get_local_charm_data(path, yaml_file): |
238 | 238 | """Retrieve Metadata of a Charm from its path |
239 | 239 |
|
240 | 240 | :patam str path: Path of charm directory or .charm file |
| 241 | + :patam str yaml_file: name of the yaml file, can be either |
| 242 | + "metadata.yaml", or "manifest.yaml" |
241 | 243 |
|
242 | 244 | :return: Object of charm metadata |
243 | 245 | """ |
244 | 246 | if str(path).endswith('.charm'): |
245 | 247 | with zipfile.ZipFile(str(path), 'r') as charm_file: |
246 | | - metadata = yaml.load(charm_file.read('metadata.yaml'), Loader=yaml.FullLoader) |
| 248 | + metadata = yaml.load(charm_file.read(yaml_file), Loader=yaml.FullLoader) |
247 | 249 | else: |
248 | 250 | entity_path = Path(path) |
249 | | - metadata_path = entity_path / 'metadata.yaml' |
| 251 | + metadata_path = entity_path / yaml_file |
250 | 252 | metadata = yaml.load(metadata_path.read_text(), Loader=yaml.FullLoader) |
251 | 253 |
|
252 | 254 | return metadata |
| 255 | + |
| 256 | + |
| 257 | +def get_local_charm_metadata(path): |
| 258 | + return get_local_charm_data(path, 'metadata.yaml') |
| 259 | + |
| 260 | + |
| 261 | +def get_local_charm_manifest(path): |
| 262 | + return get_local_charm_data(path, 'manifest.yaml') |
| 263 | + |
| 264 | + |
| 265 | +PRECISE = "precise" |
| 266 | +QUANTAL = "quantal" |
| 267 | +RARING = "raring" |
| 268 | +SAUCY = "saucy" |
| 269 | +TRUSTY = "trusty" |
| 270 | +UTOPIC = "utopic" |
| 271 | +VIVID = "vivid" |
| 272 | +WILY = "wily" |
| 273 | +XENIAL = "xenial" |
| 274 | +YAKKETY = "yakkety" |
| 275 | +ZESTY = "zesty" |
| 276 | +ARTFUL = "artful" |
| 277 | +BIONIC = "bionic" |
| 278 | +COSMIC = "cosmic" |
| 279 | +DISCO = "disco" |
| 280 | +EOAN = "eoan" |
| 281 | +FOCAL = "focal" |
| 282 | +GROOVY = "groovy" |
| 283 | +HIRSUTE = "hirsute" |
| 284 | +IMPISH = "impish" |
| 285 | +JAMMY = "jammy" |
| 286 | +KINETIC = "kinetic" |
| 287 | + |
| 288 | +UBUNTU_SERIES = { |
| 289 | + PRECISE: "12.04", |
| 290 | + QUANTAL: "12.10", |
| 291 | + RARING: "13.04", |
| 292 | + SAUCY: "13.10", |
| 293 | + TRUSTY: "14.04", |
| 294 | + UTOPIC: "14.10", |
| 295 | + VIVID: "15.04", |
| 296 | + WILY: "15.10", |
| 297 | + XENIAL: "16.04", |
| 298 | + YAKKETY: "16.10", |
| 299 | + ZESTY: "17.04", |
| 300 | + ARTFUL: "17.10", |
| 301 | + BIONIC: "18.04", |
| 302 | + COSMIC: "18.10", |
| 303 | + DISCO: "19.04", |
| 304 | + EOAN: "19.10", |
| 305 | + FOCAL: "20.04", |
| 306 | + GROOVY: "20.10", |
| 307 | + HIRSUTE: "21.04", |
| 308 | + IMPISH: "21.10", |
| 309 | + JAMMY: "22.04", |
| 310 | + KINETIC: "22.10", |
| 311 | +} |
| 312 | + |
| 313 | + |
| 314 | +def get_series_version(series_name): |
| 315 | + if series_name not in UBUNTU_SERIES: |
| 316 | + raise errors.JujuError("Unknown series : %s", series_name) |
| 317 | + return UBUNTU_SERIES[series_name] |
| 318 | + |
| 319 | + |
| 320 | +def get_version_series(version): |
| 321 | + if version not in UBUNTU_SERIES.values(): |
| 322 | + raise errors.JujuError("Unknown version : %s", version) |
| 323 | + return list(UBUNTU_SERIES.keys())[list(UBUNTU_SERIES.values()).index(version)] |
| 324 | + |
0 commit comments