forked from Forestscribe/genivi-dev-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifactory_upload.py
38 lines (33 loc) · 1.11 KB
/
artifactory_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
import os
import argh
import requests
import yaml
del os.environ["http_proxy"]
del os.environ["https_proxy"]
del os.environ["ALL_PROXY"]
@argh.dispatch_command
def main(art_output_url=None, target=None):
if art_output_url is not None:
os.environ["ART_OUTPUT_URL"] = art_output_url
if target is not None:
os.environ["TARGET"] = target
conf = yaml.load(open(".bbtravis.yml"))
to_upload = []
for upload in conf['uploads']:
destdir = upload.get('destdir')
if destdir is None:
print "warning: destdir is not defined!", upload
destdir = destdir % os.environ
files = upload.get('files')
if files is None:
print "warning: files is not defined!", upload
for fn in files:
fn = fn % os.environ
if os.path.exists(fn):
to_upload.append((fn, destdir))
print "\n".join([str(x) for x in to_upload])
for fn, destdir in to_upload:
dest_url = os.path.join(destdir, os.path.basename(fn))
f = open(fn, 'rb')
res = requests.put(dest_url, data=f)
print res.text