def get_workspace_zip(inp): conn = swift_config.getS3Connection() match = re.search("AUTH[^/]+/([^/]+)/(Allura/User/[^/]+/[^/]+/(?:workspace|config).zip)", inp) if match is None: raise Exception("Input is not in expected format. It should be the resultsPutUrl parameter") bucket_name, key_name = match.groups() #b = conn.get_bucket(bucket_name) import boto.s3 b = boto.s3.bucket.Bucket(conn, bucket_name) k = b.get_key(key_name) with open('workspace.zip', 'wb') as workspace_zip: k.get_contents_to_file(workspace_zip)
def get_workspace_zip(filename, **kwargs): conn = swift_config.getS3Connection() import boto.s3 b = boto.s3.bucket.Bucket(conn, bucket_name) key_name = kwargs.get('key_name') or os.path.basename(filename) print key_name k = b.get_key(key_name) if k is not None: print "Current key has etag " + k.etag if not kwargs.get('overwrite', False): print "Use --overwrite to overwrite current contents" return k = boto.s3.key.Key(b, key_name) k.set_contents_from_filename(filename)
def get_workspace_zip(inp): conn = swift_config.getS3Connection() match = re.search( "AUTH[^/]+/([^/]+)/(Allura/User/[^/]+/[^/]+/(?:workspace|config).zip)", inp) if match is None: raise Exception( "Input is not in expected format. It should be the resultsPutUrl parameter" ) bucket_name, key_name = match.groups() #b = conn.get_bucket(bucket_name) import boto.s3 b = boto.s3.bucket.Bucket(conn, bucket_name) k = b.get_key(key_name) with open('workspace.zip', 'wb') as workspace_zip: k.get_contents_to_file(workspace_zip)