Skip to content

Commit 7a9a0c3

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

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

scripts/backup_beta_repos.py

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

1111

1212
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+
}
1418

19+
ReposType = typing.List[typing.Dict[str, typing.Any]]
1520

1621
async def find_pulp_repos(
1722
name_starts: str,
@@ -55,15 +60,17 @@ async def create_pulp_backup_repos(
5560
return result
5661

5762

58-
async def _main(dry_run: bool = False):
63+
async def _main(repos_to_backup, dry_run: bool = False):
5964
logger = logging.getLogger(PROG_NAME)
6065
logger.debug("Acquiring Pulp connection data and creating client")
6166
host, user, password = get_pulp_params()
6267
pulp_client = PulpClient(host, user, password)
6368
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+
)
6774
backup_repos = await create_pulp_backup_repos(repos, dry_run=dry_run)
6875
fields = ["pulp_href", "sha256"]
6976
add_tasks = []
@@ -130,10 +137,25 @@ def main():
130137
parser.add_argument("-d", "--dry-run", action="store_true", default=False,
131138
help="Output everything that will happen, "
132139
"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+
)
133146
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+
]
134153
level = logging.DEBUG if args.verbose else logging.INFO
135154
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))
137159

138160

139161
if __name__ == "__main__":

0 commit comments

Comments
 (0)