From 09f205c5f3096cb15068303cf800aae87ac81bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Mon, 4 Aug 2025 16:02:33 +0200 Subject: [PATCH] import_srpm: allow to pass a url as source file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫtan Lehmann --- scripts/import_srpm.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts/import_srpm.py b/scripts/import_srpm.py index 34da7aaa..fb393f61 100755 --- a/scripts/import_srpm.py +++ b/scripts/import_srpm.py @@ -3,11 +3,21 @@ import logging import os import subprocess +from urllib.parse import urlparse +from urllib.request import urlretrieve + def call_process(args): logging.debug("$ %s", args) subprocess.check_call(args) +def is_url(url_string): + try: + result = urlparse(url_string) + return all([result.scheme, result.netloc]) + except ValueError: + return False + def main(): parser = argparse.ArgumentParser(description='Imports the contents of a source RPM into a git repository') parser.add_argument('source_rpm', help='local path to source RPM') @@ -28,12 +38,19 @@ def main(): }[args.verbose] logging.basicConfig(format='[%(levelname)s] %(message)s', level=loglevel) + source_rpm = args.source_rpm + if is_url(source_rpm): + # get the src.rpm locally, and continue with the actual file + local_filename = f'/tmp/{os.path.basename(source_rpm)}' + urlretrieve(source_rpm, local_filename) + source_rpm = local_filename + # check that the source RPM file exists - if not os.path.isfile(args.source_rpm): - parser.error("File %s does not exist." % args.source_rpm) - if not args.source_rpm.endswith('.src.rpm'): - parser.error("File %s does not appear to be a source RPM." % args.source_rpm) - source_rpm_abs = os.path.abspath(args.source_rpm) + if not os.path.isfile(source_rpm): + parser.error("File %s does not exist." % source_rpm) + if not source_rpm.endswith('.src.rpm'): + parser.error("File %s does not appear to be a source RPM." % source_rpm) + source_rpm_abs = os.path.abspath(source_rpm) # enter repository directory if not os.path.isdir(args.repository): @@ -107,7 +124,7 @@ def main(): if not has_changes: print("\nWorking copy has no modifications. Nothing to commit. No changes from previous release?\n") else: - msg = 'Import %s' % os.path.basename(args.source_rpm) + msg = 'Import %s' % os.path.basename(source_rpm) if deleted: msg += "\n\nFiles deleted for legal reasons:\n - " + '\n - '.join(deleted) call_process(['git', 'commit', '-s', '-m', msg])