From 8bce7f181761a96fa2d0b145e7f9558f3e225b85 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 21 Dec 2021 14:39:32 +0100 Subject: [PATCH] update and not overwrite the existing list of galaxy platforms Signed-off-by: Daniel Ziegenberg --- src/ansibleschemas/__main__.py | 21 ++++++++++++++------- src/ansibleschemas/_galaxy.py | 4 +++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ansibleschemas/__main__.py b/src/ansibleschemas/__main__.py index 82eb3878..239f1d04 100644 --- a/src/ansibleschemas/__main__.py +++ b/src/ansibleschemas/__main__.py @@ -6,11 +6,11 @@ import subprocess from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import Dict, List import requests from rich.progress import Progress +from ansibleschemas._galaxy import GALAXY_PLATFORMS from ansibleschemas.ansiblelint import AnsibleLintModel from ansibleschemas.api import ansible_modules from ansibleschemas.galaxy import GalaxyFileModel @@ -28,6 +28,10 @@ out_dir = Path(os.getcwd()) / "f" module_dir = Path(__file__).resolve().parents[0] +GALAXY_FILE_HEADER = """from typing import Dict, List + +GALAXY_PLATFORMS: Dict[str, List[str]]""" + def parse_args() -> Namespace: """Parse commandline arguments.""" @@ -87,7 +91,6 @@ def dump_galaxy_platforms() -> None: """Dumps galaxy platforms into a python module.""" filename = f"{module_dir}/_galaxy.py" print(f"Dumping list of Galaxy platforms to {filename}") - platforms: Dict[str, List[str]] = {} result = {'next_link': '/api/v1/platforms/'} while result.get('next_link', None): url = GALAXY_API_URL + result['next_link'] @@ -99,13 +102,17 @@ def dump_galaxy_platforms() -> None: release = entry.get('release', None) if not name or not isinstance(name, str): continue - if name and name not in platforms: - platforms[name] = [] - if release not in ['any', 'None'] and release not in platforms[name]: - platforms[name].append(release) + if name and name not in GALAXY_PLATFORMS: + GALAXY_PLATFORMS[name] = [] + if ( + release not in ['any', 'all', 'None'] + and release not in GALAXY_PLATFORMS[name] + ): + GALAXY_PLATFORMS[name].append(release) + GALAXY_PLATFORMS[name].sort() with open(filename, "w") as file: - file.write(f"GALAXY_PLATFORMS = {pretty_plattforms(platforms)}\n") + file.write(f"{GALAXY_FILE_HEADER} = {pretty_plattforms(GALAXY_PLATFORMS)}\n") def dump_module_doc(module): diff --git a/src/ansibleschemas/_galaxy.py b/src/ansibleschemas/_galaxy.py index 3f3dc737..9afa9804 100644 --- a/src/ansibleschemas/_galaxy.py +++ b/src/ansibleschemas/_galaxy.py @@ -1,4 +1,6 @@ -GALAXY_PLATFORMS = { +from typing import Dict, List + +GALAXY_PLATFORMS: Dict[str, List[str]] = { 'AIX': ['6.1', '7.1', '7.2'], 'Alpine': [], 'Amazon': [