33import logging
44import os
55import subprocess
6+ from urllib .parse import urlparse
7+ from urllib .request import urlretrieve
8+
69
710def call_process (args ):
811 logging .debug ("$ %s" , args )
912 subprocess .check_call (args )
1013
14+ def is_url (url_string ):
15+ try :
16+ result = urlparse (url_string )
17+ return all ([result .scheme , result .netloc ])
18+ except ValueError :
19+ return False
20+
1121def main ():
1222 parser = argparse .ArgumentParser (description = 'Imports the contents of a source RPM into a git repository' )
1323 parser .add_argument ('source_rpm' , help = 'local path to source RPM' )
@@ -28,12 +38,19 @@ def main():
2838 }[args .verbose ]
2939 logging .basicConfig (format = '[%(levelname)s] %(message)s' , level = loglevel )
3040
41+ source_rpm = args .source_rpm
42+ if is_url (source_rpm ):
43+ # get the src.rpm locally, and continue with the actual file
44+ local_filename = f'/tmp/{ os .path .basename (source_rpm )} '
45+ urlretrieve (source_rpm , local_filename )
46+ source_rpm = local_filename
47+
3148 # check that the source RPM file exists
32- if not os .path .isfile (args . source_rpm ):
33- parser .error ("File %s does not exist." % args . source_rpm )
34- if not args . source_rpm .endswith ('.src.rpm' ):
35- parser .error ("File %s does not appear to be a source RPM." % args . source_rpm )
36- source_rpm_abs = os .path .abspath (args . source_rpm )
49+ if not os .path .isfile (source_rpm ):
50+ parser .error ("File %s does not exist." % source_rpm )
51+ if not source_rpm .endswith ('.src.rpm' ):
52+ parser .error ("File %s does not appear to be a source RPM." % source_rpm )
53+ source_rpm_abs = os .path .abspath (source_rpm )
3754
3855 # enter repository directory
3956 if not os .path .isdir (args .repository ):
@@ -107,7 +124,7 @@ def main():
107124 if not has_changes :
108125 print ("\n Working copy has no modifications. Nothing to commit. No changes from previous release?\n " )
109126 else :
110- msg = 'Import %s' % os .path .basename (args . source_rpm )
127+ msg = 'Import %s' % os .path .basename (source_rpm )
111128 if deleted :
112129 msg += "\n \n Files deleted for legal reasons:\n - " + '\n - ' .join (deleted )
113130 call_process (['git' , 'commit' , '-s' , '-m' , msg ])
0 commit comments