-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend_to_bucket.py
More file actions
37 lines (26 loc) · 1.11 KB
/
send_to_bucket.py
File metadata and controls
37 lines (26 loc) · 1.11 KB
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
import os
import sys
from bucket_management import ClBucketManagement
API_KEY = os.getenv("CELLAR_ADDON_KEY_ID")
HOST = os.getenv("CELLAR_ADDON_HOST",)
SECRET_KEY = os.getenv("CELLAR_ADDON_KEY_SECRET",)
def main():
if len(sys.argv) != 3:
raise Exception("Usage : %s bucket_target file" % sys.argv[0])
path = os.path.join(os.getcwd(), sys.argv[2])
if not os.path.exists(path):
path = sys.argv[2]
if not os.path.exists(path):
raise Exception("%s is not a relative or an absolute path" % sys.argv[2])
if not os.path.isfile(path):
raise Exception("%s is not a file" % path)
bucket_manager = ClBucketManagement(api_key=API_KEY,
secret_key=SECRET_KEY,
host=HOST)
bucket_name = sys.argv[1]
if bucket_name in bucket_manager.get_all_bucket():
bucket_manager.delete_bucket(bucket_name, allow_full_bucket_deletion=True)
bucket_manager.create_bucket(bucket_name)
bucket_manager.save_big_files(bucket_name, os.path.basename(path), path)
if __name__ == '__main__':
main()