本文整理汇总了Python中boto.s3.bucket.Bucket.get_all_keys方法的典型用法代码示例。如果您正苦于以下问题:Python Bucket.get_all_keys方法的具体用法?Python Bucket.get_all_keys怎么用?Python Bucket.get_all_keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.s3.bucket.Bucket
的用法示例。
在下文中一共展示了Bucket.get_all_keys方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Compost
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
class Compost(object):
def __init__(self, directory, bucket):
self.directory = directory
self.bucket = Bucket(connection=boto.connect_s3(), name=bucket)
def turn(self):
"""
'Turn' the compost, i.e. make a backup of all files in the local directory.
"""
for filename, full_path in self._local_files():
logger.debug('backing up {}'.format(filename))
key = self.bucket.new_key(filename)
key.set_contents_from_filename(full_path)
def list(self):
"""Return a list of known backed up files."""
return [k.name for k in self.bucket.get_all_keys()]
def read(self, filename):
"""
Return the contents of named file, or the empty string if the files does not exist.
"""
return self.bucket.get_key(filename).get_contents_as_string()
def _local_files(self):
for f in os.listdir(self.directory):
yield f, os.path.join(self.directory, f)
示例2: empty_bucket
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def empty_bucket(bucket_name):
"""Destructive helper."""
import boto
from boto.s3.bucket import Bucket
bucket = Bucket(connection=boto.connect_s3(), name=bucket_name)
for key in bucket.get_all_keys():
key.delete()
示例3: get_bucket
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def get_bucket(self, bucket_name, validate=True):
bucket = Bucket(self, bucket_name)
if validate:
rs = bucket.get_all_keys(None, maxkeys=0)
return bucket
示例4: get_bucket
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def get_bucket(self, bucket_name, validate=True, headers=None):
bucket = Bucket(self, bucket_name)
if validate:
bucket.get_all_keys(headers, maxkeys=0)
return bucket
示例5: dirwalk
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def dirwalk(dir):
for f in os.listdir(dir):
fullpath = os.path.join(dir,f)
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
for x in dirwalk(fullpath):
yield x
else:
yield fullpath
bucketname = 'ergometria.async.fi'
connection = boto.connect_s3()
bucket = Bucket(connection, bucketname)
keynames = [key.name for key in bucket.get_all_keys(prefix='data/')]
datafile_uploaded = False
for filename in dirwalk('data/'):
if not filename in keynames and not filename.endswith('.json'):
datafile_uploaded = True
print 'uploading', filename
k = Key(bucket)
k.key = filename
k.set_contents_from_filename(filename)
if True: #datafile_uploaded:
k = Key(bucket)
k.key = 'data/index.json'
sessions = []
示例6: get_bucket
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def get_bucket(self, bucket_name, validate=True):
bucket = Bucket(self, bucket_name, headers=self.headers)
if validate:
rs = bucket.get_all_keys(maxkeys=0)
return bucket
示例7: get_bucket
# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_all_keys [as 别名]
def get_bucket(self, bucket_name):
bucket = Bucket(self, bucket_name)
rs = bucket.get_all_keys(None, maxkeys=0)
return bucket