Skip to content

Commit c5bfc6c

Browse files
committed
Take beta repos to backup from commandline arguments
Also, get rid of AlmaLinux 8 in the script, we don't need them anymore. Resolves: AlmaLinux/build-system#507
1 parent e8ef3bf commit c5bfc6c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

scripts/backup_beta_repos.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111

1212
PROG_NAME = "backup_beta_repositories"
13-
ReposType = typing.List[typing.Dict[str, typing.Any]]
13+
PLATFORM_REPO_MAP = {
14+
"almalinux_9": "AlmaLinux-9-beta",
15+
"almalinux_10": "almalinux10-beta",
16+
}
1417

18+
ReposType = typing.List[typing.Dict[str, typing.Any]]
1519

1620
async def find_pulp_repos(
1721
name_starts: str,
@@ -55,15 +59,17 @@ async def create_pulp_backup_repos(
5559
return result
5660

5761

58-
async def _main(dry_run: bool = False):
62+
async def _main(repos_to_backup, dry_run: bool = False):
5963
logger = logging.getLogger(PROG_NAME)
6064
logger.debug("Acquiring Pulp connection data and creating client")
6165
host, user, password = get_pulp_params()
6266
pulp_client = PulpClient(host, user, password)
6367
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))
68+
repos = []
69+
for repo_to_backup in repos_to_backup:
70+
repos.extend(
71+
await find_pulp_repos(repo_to_backup, pulp_client=pulp_client)
72+
)
6773
backup_repos = await create_pulp_backup_repos(repos, dry_run=dry_run)
6874
fields = ["pulp_href", "sha256"]
6975
add_tasks = []
@@ -130,10 +136,24 @@ def main():
130136
parser.add_argument("-d", "--dry-run", action="store_true", default=False,
131137
help="Output everything that will happen, "
132138
"but do not create/modify anything")
139+
for platform in PLATFORM_REPO_MAP:
140+
parser.add_argument(
141+
f"--{platform}", f"--{platform.replace('_', '-')}",
142+
help=f"Create backups of {platform} beta repos",
143+
action="store_true"
144+
)
133145
args = parser.parse_args()
146+
147+
repos_to_backup = [
148+
PLATFORM_REPO_MAP[platform]
149+
for platform in PLATFORM_REPO_MAP
150+
if getattr(args, platform)
151+
]
134152
level = logging.DEBUG if args.verbose else logging.INFO
135153
logging.basicConfig(level=level)
136-
asyncio.run(_main(dry_run=args.dry_run))
154+
if not repos_to_backup:
155+
logging.info("You need to specify at least one platform")
156+
asyncio.run(_main(repos_to_backup, dry_run=args.dry_run))
137157

138158

139159
if __name__ == "__main__":

0 commit comments

Comments
 (0)