-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathupload-ucloud.py
70 lines (50 loc) · 1.68 KB
/
upload-ucloud.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# /usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Author: samzong.lu
E-mail: [email protected]
"""
import logging
import os
import sys
import subprocess
import time
from alert_webhook import alter_webhook
def do_upload_cli(file, public_key, private_key, region, bucket):
cmd = '../scripts/tools/us3cli-linux64'
bucket = 'us3://' + bucket
if not os.path.exists(cmd):
logging.error('can not find us3cli command')
return 'error'
subprocess.run(['chmod', '+x', cmd])
if os.path.isdir(file):
out = subprocess.run(
[cmd, 'cp', '-r', file, bucket, '--accesskey', public_key, '--secretkey',
private_key,
'--endpoint',
region])
elif os.path.isfile(file):
out = subprocess.run(
[cmd, 'cp', file, bucket, '--accesskey', public_key, '--secretkey', private_key,
'--endpoint',
region])
if out.returncode != 0:
raise Exception("ucloud upload error", out.returncode)
if __name__ == '__main__':
argv = sys.argv
if len(argv) != 5:
raise Exception('args not right', argv)
else:
public_key = argv[1].split('=')[1]
private_key = argv[2].split('=')[1]
region = argv[3].split('=')[1]
bucket = argv[4].split('=')[1]
logging.debug(public_key + private_key + region + bucket)
try:
for file in os.listdir():
logging.info(file)
do_upload_cli(file, public_key, private_key, region, bucket)
alter_webhook(bucket, message="success")
except Exception as e:
logging.error(e)
alter_webhook(bucket, message="error")