本文整理汇总了Python中swiftclient.service.SwiftService.stat方法的典型用法代码示例。如果您正苦于以下问题:Python SwiftService.stat方法的具体用法?Python SwiftService.stat怎么用?Python SwiftService.stat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swiftclient.service.SwiftService
的用法示例。
在下文中一共展示了SwiftService.stat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DiracStore
# 需要导入模块: from swiftclient.service import SwiftService [as 别名]
# 或者: from swiftclient.service.SwiftService import stat [as 别名]
class DiracStore(object):
def __init__(self, container, topic, kafka):
self.container = container
self.swift = SwiftService()
self.out = OutputManager()
self.kafka = kafka
auth = get_auth()
self.url = auth[0]
self.token = auth[1]
self.topic = topic
self.producer = KafkaProducer(bootstrap_servers=kafka)
def send(self, resource):
json = message_to_json(resource)
print("sending " + json)
self.producer.send(self.topic, json.encode('utf-8'))
def make_resource(self, stat):
resource = schema.Resource()
resource.type = 'file'
resource.name = stat['Object']
resource.location = self.url + '/' + self.container + '/' + stat['Object']
resource.mimeType = stat['Content Type']
resource.size = long(stat['Content Length'])
resource.created = stat['Last Modified']
return resource
def stat(self, paths):
stat = {}
for response in self.swift.stat(container=self.container, objects=paths):
if response['success']:
stat[response['object']] = {item[0]: item[1] for item in response['items']}
return stat
def store(self, path, source):
isdir = os.path.isdir(source)
base = source if isdir else os.path.dirname(source)
sources = os.listdir(source) if isdir else [source]
locations = [os.path.join(path, os.path.basename(file)) for file in sources]
print(str(len(locations)) + " locations!")
stats = self.stat(locations)
objs = [SwiftUploadObject(os.path.join(base, os.path.basename(location)), object_name=location) for location in locations if not location in stats]
print(str(len(objs)) + " previously unseen!")
for response in self.swift.upload(self.container, objs):
if response['success']:
if 'object' in response:
print('uploading ' + response['object'])
stat = self.stat([response['object']])
resource = self.make_resource(stat.values()[0])
self.send(resource)
示例2: ck_cdn
# 需要导入模块: from swiftclient.service import SwiftService [as 别名]
# 或者: from swiftclient.service.SwiftService import stat [as 别名]
def ck_cdn(self, secrets):
if self.client.rax_id:
rax_id = self.client.rax_id
p_okg("client.rax_id: {}".format(rax_id))
else:
p_warn("client.rax_id not set.")
return
if self.client.bucket_id:
bucket_id = self.client.bucket_id
p_okg("client.bucket_id: {}".format(bucket_id))
else:
p_fail("client.bucket_id not set.")
print("logging in...")
uploader = swift_uploader.Uploader()
# pprint.pprint(pw.swift[rax_id])
uploader.user=rax_id
cf = uploader.auth()
print("checking for valid bucket...")
from swiftclient.service import SwiftService
swift = SwiftService()
stats_it = swift.stat(container=bucket_id)
"""
containers = cf.get_all_containers()
container_names = [container.name for container in containers]
print("container_names", container_names)
if bucket_id in container_names:
p_okg('"{}" found.'.format(bucket_id))
else:
p_fail('"{}" not found.'.format(bucket_id))
"""
# not sure what to do with this...
# container = cf.get_container(bucket_id)
return