diff --git a/scripts/import_srpm.py b/scripts/import_srpm.py index 34da7aa..fb393f6 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])