|
10 | 10 |
|
11 | 11 |
|
12 | 12 | PROG_NAME = "backup_beta_repositories" |
13 | | -ReposType = typing.List[typing.Dict[str, typing.Any]] |
| 13 | +# We search using startswith |
| 14 | +PLATFORM_REPO_MAP = { |
| 15 | + "almalinux_9": "AlmaLinux-9-beta-AlmaLinux-9", |
| 16 | + "almalinux_10": "eabdullin1-almalinux10-beta-almalinux-10", |
| 17 | +} |
14 | 18 |
|
| 19 | +ReposType = typing.List[typing.Dict[str, typing.Any]] |
15 | 20 |
|
16 | 21 | async def find_pulp_repos( |
17 | 22 | name_starts: str, |
@@ -55,15 +60,17 @@ async def create_pulp_backup_repos( |
55 | 60 | return result |
56 | 61 |
|
57 | 62 |
|
58 | | -async def _main(dry_run: bool = False): |
| 63 | +async def _main(repos_to_backup, dry_run: bool = False): |
59 | 64 | logger = logging.getLogger(PROG_NAME) |
60 | 65 | logger.debug("Acquiring Pulp connection data and creating client") |
61 | 66 | host, user, password = get_pulp_params() |
62 | 67 | pulp_client = PulpClient(host, user, password) |
63 | 68 | logger.info("Searching for all beta repositories") |
64 | | - repos = await find_pulp_repos("almalinux8-beta", pulp_client=pulp_client) |
65 | | - repos.extend(await find_pulp_repos( |
66 | | - "AlmaLinux-9-beta", pulp_client=pulp_client)) |
| 69 | + repos = [] |
| 70 | + for repo_to_backup in repos_to_backup: |
| 71 | + repos.extend( |
| 72 | + await find_pulp_repos(repo_to_backup, pulp_client=pulp_client) |
| 73 | + ) |
67 | 74 | backup_repos = await create_pulp_backup_repos(repos, dry_run=dry_run) |
68 | 75 | fields = ["pulp_href", "sha256"] |
69 | 76 | add_tasks = [] |
@@ -130,10 +137,25 @@ def main(): |
130 | 137 | parser.add_argument("-d", "--dry-run", action="store_true", default=False, |
131 | 138 | help="Output everything that will happen, " |
132 | 139 | "but do not create/modify anything") |
| 140 | + for platform in PLATFORM_REPO_MAP: |
| 141 | + parser.add_argument( |
| 142 | + f"--{platform}", f"--{platform.replace('_', '-')}", |
| 143 | + help=f"Create backups of {platform} beta repos", |
| 144 | + action="store_true" |
| 145 | + ) |
133 | 146 | args = parser.parse_args() |
| 147 | + |
| 148 | + repos_to_backup = [ |
| 149 | + PLATFORM_REPO_MAP[platform] |
| 150 | + for platform in PLATFORM_REPO_MAP |
| 151 | + if getattr(args, platform) |
| 152 | + ] |
134 | 153 | level = logging.DEBUG if args.verbose else logging.INFO |
135 | 154 | logging.basicConfig(level=level) |
136 | | - asyncio.run(_main(dry_run=args.dry_run)) |
| 155 | + if not repos_to_backup: |
| 156 | + logging.info("You need to specify at least one platform") |
| 157 | + else: |
| 158 | + asyncio.run(_main(repos_to_backup, dry_run=args.dry_run)) |
137 | 159 |
|
138 | 160 |
|
139 | 161 | if __name__ == "__main__": |
|
0 commit comments