Michael Still | 0925882 | 2013-12-07 07:42:19 +1100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import json |
| 4 | import os |
| 5 | import pyrax |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | def 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 | |
| 20 | def 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 | |
| 32 | if __name__ == '__main__': |
| 33 | push(sys.argv[1], sys.argv[2], sys.argv[3]) |