| #!/usr/bin/python |
| |
| import json |
| import os |
| import pyrax |
| import sys |
| |
| |
| def copy_dir(topdir, path, container): |
| for ent in os.listdir(path): |
| fullpath = os.path.join(path, ent) |
| shortpath = fullpath.replace(topdir + '/', '') |
| if os.path.isdir(fullpath): |
| copy_dir(topdir, fullpath, container) |
| else: |
| print shortpath |
| container.upload_file(fullpath, obj_name=shortpath) |
| |
| |
| def push(topdir, region, container_name): |
| pyrax.set_setting('identity_type', 'rackspace') |
| with open(os.path.expanduser('~/.cloudfiles'), 'r') as f: |
| conf = json.loads(f.read()) |
| pyrax.set_credentials(conf['access_key'], |
| conf['secret_key'], |
| region=region) |
| conn = pyrax.connect_to_cloudfiles(region=region.upper(), public=False) |
| container = conn.create_container(container_name) |
| copy_dir(topdir, topdir, container) |
| |
| |
| if __name__ == '__main__': |
| push(sys.argv[1], sys.argv[2], sys.argv[3]) |