-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupload.py
49 lines (42 loc) · 1.64 KB
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from subutai_bazaar import cdn
import optparse
import sys
import os.path
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option('-t', '--host', action='store', dest='host',
help='hostname of the CDN', default='bazaar.subutai.io')
parser.add_option('-f', '--file', action='store', dest='srcfile',
help='file to upload', default='')
parser.add_option('-u', '--user', action='store', dest='gpguser',
help='GPG key ID', default='')
parser.add_option('-p', '--fingerprint',
action='store',
dest='fingerprint',
help='GPG fingerprint',
default='')
options, args = parser.parse_args()
if options.srcfile == '':
print("Specify source file with --file=<pathtofile> option")
sys.exit(2)
if options.gpguser == '':
print("Specify GPG key ID with --user=<id> option")
sys.exit(3)
if options.fingerprint == '':
print("Specify fingerprint with --fingerprint=<fingerprint> option")
sys.exit(4)
if not os.path.isfile(options.srcfile):
print("Specified file was not found")
sys.exit(5)
c = cdn.CDN(options.host,
user=options.gpguser,
fingerprint=options.fingerprint, verify=False)
try:
result = c.Upload(options.srcfile)
if result is None:
print("File upload failed")
sys.exit(2)
print("File was succesfully uploaded")
except Exception as e:
print("Error occured during upload: " + str(e))
sys.exit(2)