當前位置: 首頁>>代碼示例>>Python>>正文


Python SwiftService.stat方法代碼示例

本文整理匯總了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)
開發者ID:,項目名稱:,代碼行數:57,代碼來源:

示例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
開發者ID:,項目名稱:,代碼行數:40,代碼來源:


注:本文中的swiftclient.service.SwiftService.stat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。