3
3
import logging
4
4
import os
5
5
import subprocess
6
+ from urllib .parse import urlparse
7
+ from urllib .request import urlretrieve
8
+
6
9
7
10
def call_process (args ):
8
11
logging .debug ("$ %s" , args )
9
12
subprocess .check_call (args )
10
13
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
+
11
21
def main ():
12
22
parser = argparse .ArgumentParser (description = 'Imports the contents of a source RPM into a git repository' )
13
23
parser .add_argument ('source_rpm' , help = 'local path to source RPM' )
@@ -28,12 +38,19 @@ def main():
28
38
}[args .verbose ]
29
39
logging .basicConfig (format = '[%(levelname)s] %(message)s' , level = loglevel )
30
40
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
+
31
48
# 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 )
37
54
38
55
# enter repository directory
39
56
if not os .path .isdir (args .repository ):
@@ -107,7 +124,7 @@ def main():
107
124
if not has_changes :
108
125
print ("\n Working copy has no modifications. Nothing to commit. No changes from previous release?\n " )
109
126
else :
110
- msg = 'Import %s' % os .path .basename (args . source_rpm )
127
+ msg = 'Import %s' % os .path .basename (source_rpm )
111
128
if deleted :
112
129
msg += "\n \n Files deleted for legal reasons:\n - " + '\n - ' .join (deleted )
113
130
call_process (['git' , 'commit' , '-s' , '-m' , msg ])
0 commit comments