Skip to content

import_srpm: allow to pass a url as source file #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions scripts/import_srpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use a temporary directory known not to conflict with anything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it could also self-destroy at the end, as python's tempfile (IIRC) allows?

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):
Expand Down Expand Up @@ -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])
Expand Down