11#!/usr/bin/python3
22
3+ import argparse
34import dnf .subject
45import hawkey
56import os
@@ -41,13 +42,23 @@ def assert_epochs_match(overrides_epoch: int, rpmfile_epoch: str):
4142 f" and overrides file entry ({ overrides_epoch } )" )
4243
4344
44- assert os .path .isdir ("builds" ), "Missing builds/ dir; is this a cosa workdir?"
45+ parser = argparse .ArgumentParser (description = 'Download override RPMs from koji.' )
46+ parser .add_argument ('--downloaddir' , default = 'overrides/rpm' ,
47+ help = 'Directory to download override RPMs to (default: overrides/rpm).' )
48+ parser .add_argument ('--lockfiledir' , default = 'src/config' ,
49+ help = 'Directory to check lock file (default: src/config).' )
50+
51+ args = parser .parse_args ()
52+
53+ for path in [args .downloaddir , args .lockfiledir ]:
54+ assert os .path .isdir (path ), f"Not found: { path } "
55+
56+ print (f"Download override rpms to { args .downloaddir } /" )
4557
4658rpms = set ()
47- os .makedirs ('overrides/rpm' , exist_ok = True )
48- for filename in os .listdir (os .path .join ("src/config" )):
59+ for filename in os .listdir (args .lockfiledir ):
4960 if is_override_lockfile (filename ):
50- with open (f'src/config/ { filename } ' ) as f :
61+ with open (os . path . join ( args . lockfiledir , filename ) ) as f :
5162 lockfile = yaml .safe_load (f )
5263 if lockfile is None or 'packages' not in lockfile :
5364 continue
@@ -58,13 +69,13 @@ def assert_epochs_match(overrides_epoch: int, rpmfile_epoch: str):
5869 rpminfo = get_rpminfo (f"{ pkg } -{ pkgobj ['evra' ]} " )
5970 rpmnvra = f"{ rpminfo .name } -{ rpminfo .version } -{ rpminfo .release } .{ rpminfo .arch } "
6071 rpms .add (rpmnvra )
61- subprocess .check_call (['koji' , 'download-build' , '--rpm' , rpmnvra ], cwd = 'overrides/rpm' )
72+ subprocess .check_call (['koji' , 'download-build' , '--rpm' , rpmnvra ], cwd = args . downloaddir )
6273 # Make sure the epoch matches what was in the overrides file
6374 # otherwise we can get errors: https://github.com/coreos/fedora-coreos-config/pull/293
6475 cp = subprocess .run (['rpm' , '-qp' , '--queryformat' , '%{E}' , f'{ rpmnvra } .rpm' ],
6576 check = True ,
6677 capture_output = True ,
67- cwd = 'overrides/rpm' )
78+ cwd = args . downloaddir )
6879 rpmfile_epoch = cp .stdout .decode ('utf-8' )
6980 assert_epochs_match (rpminfo .epoch , rpmfile_epoch )
7081
0 commit comments