-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploader
executable file
·41 lines (31 loc) · 1.22 KB
/
uploader
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
#! /usr/local/bin/python2.7
"""
usage: ./uploader -f uploader -d test
"""
import argparse
import os
import subprocess
import load_secrets.api
import global_settings
artifactory_url_prefix = 'artifactory_prefix'
def upload(credentials, source, target):
_opts = [
'-s',
'-u "{0[username]}:{0[password]}"'.format(credentials),
'''-H "X-Checksum-Sha1:$(sha1sum {source} | cut -d ' ' -f1 )"'''.format(source=source),
'-T "{source}"'.format(source=source),
]
cmd = 'curl {opts} "{target}"'.format(opts=' '.join(_opts), target=target)
return subprocess.check_output(cmd, shell=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", dest='filename', required=True)
parser.add_argument("-d", "--worker", dest='worker_name', required=True)
args = parser.parse_args()
secrets = load_secrets.api.load('artifactory', server_secrets_path_prefix=global_settings.secrets_path)
target = '{url_prefix}/{args.worker_name}/{file_name}'.format(
url_prefix=artifactory_url_prefix,
args=args,
file_name=os.path.basename(args.filename),
)
print upload(credentials=secrets, source=args.filename, target=target)