-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhsm_copy.py
executable file
·50 lines (38 loc) · 1.24 KB
/
hsm_copy.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
#!/usr/bin/env python
import os
from boto.s3.key import Key
from boto.s3.connection import S3Connection
import imp
config = None
s3conn = None
BASEDIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
def load_common():
common = imp.load_source('', os.path.join(BASEDIR, 'common.py'))
return common
common = load_common()
def copy_file_to_s3(inpath, remote_path):
"""
Copies file to regulsr s3 storage.
"""
bucket = s3conn.create_bucket(config.ORG_BUCKET)
key = Key(bucket)
key.key = remote_path
key.set_contents_from_filename(inpath)
# print key.etag
return key
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--in-tar", required=True, type=str)
parser.add_argument('--dest', type=str, help='AWS S3 object key')
parser.add_argument(
'--config', default=common.DEF_CONFIG_PATH, type=str,
help='Path to config containing AWS auth info, default is %s' %
common.DEF_CONFIG_PATH
)
args = parser.parse_args()
common.load_config(args.config)
config = common.config
s3conn = S3Connection(
config.AWS_ACCESS_KEY_ID, config.AWS_SECRET_KEY)
copy_file_to_s3(args.in_tar, args.dest)