blob: cef60cad69defb38dc3cd9dd1e521e3c1b97e152 [file] [log] [blame]
Michael Still09258822013-12-07 07:42:19 +11001#!/usr/bin/python
2
3import json
4import os
5import pyrax
6import sys
7
8
9def copy_dir(topdir, path, container):
10 for ent in os.listdir(path):
11 fullpath = os.path.join(path, ent)
12 shortpath = fullpath.replace(topdir + '/', '')
13 if os.path.isdir(fullpath):
14 copy_dir(topdir, fullpath, container)
15 else:
16 print shortpath
17 container.upload_file(fullpath, obj_name=shortpath)
18
19
20def push(topdir, region, container_name):
21 pyrax.set_setting('identity_type', 'rackspace')
22 with open(os.path.expanduser('~/.cloudfiles'), 'r') as f:
23 conf = json.loads(f.read())
24 pyrax.set_credentials(conf['access_key'],
25 conf['secret_key'],
26 region=region)
27 conn = pyrax.connect_to_cloudfiles(region=region.upper(), public=False)
28 container = conn.create_container(container_name)
29 copy_dir(topdir, topdir, container)
30
31
32if __name__ == '__main__':
33 push(sys.argv[1], sys.argv[2], sys.argv[3])