-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3video.py
executable file
·44 lines (32 loc) · 1.14 KB
/
s3video.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
#!/usr/bin/env python
# Push the files under 'topdir' into 'bucketname'
# Expects a virtualenv with Boto installed
# Arguments: bucketname, topdir
import logging
import os
import sys
from boto.s3.connection import S3Connection
from boto.s3.key import Key
logging.basicConfig(level=logging.INFO)
if len(sys.argv) < 3:
logging.error('Usage: %s BUCKETNAME TOPDIR [TOPDIRSTRIP]' % sys.argv[0])
logging.error('Example: %s mybucket /tmp/upload/videos /tmp/upload' % sys.argv[0])
raise RuntimeError, 'Fix arguments and try again.'
bucketname = sys.argv[1]
topdir = os.path.expanduser(sys.argv[2])
topdirstrip = sys.argv[3]
if not os.path.isdir(topdir):
raise RuntimeError, 'No such topdir=%s' % topdir
# TODO: how do I pick the primary region?
conn = S3Connection()
bucket = conn.create_bucket(bucketname)
k = Key(bucket)
logging.info('All your buckets: %s' % conn.get_all_buckets())
for root, dirs, files in os.walk(topdir):
for name in files:
path = os.path.join(root, name)
k.key = path
if topdirstrip:
k.key = path.partition(topdirstrip)[2]
logging.info('%s' % k.key)
k.set_contents_from_filename(path)