当前位置: 首页>>代码示例>>Python>>正文


Python oss2.ObjectIterator方法代码示例

本文整理汇总了Python中oss2.ObjectIterator方法的典型用法代码示例。如果您正苦于以下问题:Python oss2.ObjectIterator方法的具体用法?Python oss2.ObjectIterator怎么用?Python oss2.ObjectIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oss2的用法示例。


在下文中一共展示了oss2.ObjectIterator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_object_iterator

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def test_object_iterator(self):
        # ObjectIterator without payer setting, should be failed.
        access_err_flag = False
        try:
            obj_iter = oss2.ObjectIterator(self.payer_bucket)
            for obj in obj_iter:
                pass
        except oss2.exceptions.AccessDenied:
            access_err_flag = True

        self.assertEqual(access_err_flag, True)

        # ObjectIterator with payer setting, should be failed.
        headers = dict()
        headers[OSS_REQUEST_PAYER] = "requester"
        obj_iter = oss2.ObjectIterator(self.payer_bucket, headers=headers)
        for obj in obj_iter:
            pass 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:20,代码来源:test_object_request_payment.py

示例2: listdir

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def listdir(self, name):
        if name == ".":
            name = ""
        name = self._get_key_name(name)
        if not name.endswith('/'):
            name += "/"
        logger().debug("name: %s", name)

        files = []
        dirs = []

        for obj in ObjectIterator(self.bucket, prefix=name, delimiter='/'):
            if obj.is_prefix():
                dirs.append(obj.key)
            else:
                files.append(obj.key)

        logger().debug("dirs: %s", list(dirs))
        logger().debug("files: %s", files)
        return dirs, files 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:22,代码来源:backends.py

示例3: listdir

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def listdir(self, name):
        name = self._normalize_name(self._clean_name(name))
        if name and name.endswith('/'):
            name = name[:-1]

        files = []
        dirs = set()

        for obj in ObjectIterator(self.bucket, prefix=name, delimiter='/'):
            if obj.is_prefix():
                dirs.add(obj.key)
            else:
                files.append(obj.key)

        return list(dirs), files 
开发者ID:007gzs,项目名称:dingtalk-django-example,代码行数:17,代码来源:storage.py

示例4: get_oss_version

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def get_oss_version(project=None):
    versions = []
    try:
        if project:
            tt = time.strftime('%Y',time.localtime())
            auth = oss2.Auth(oss_id, oss_key)
            bucket = oss2.Bucket(auth, oss_url, 'ops')
            db_packages = db_op.k8s_packages
            packages = db_packages.query.with_entities(db_packages.package).filter(db_packages.deployment==project).all()
            if packages:
                package_name = packages[0][0].split('.')[0]
                for obj in oss2.ObjectIterator(bucket):
                    if obj.key.endswith('.war') or obj.key.endswith('.tar.gz') or obj.key.endswith('.jar'):
                        obj_name  = obj.key.split('/')[-1].replace('_','-')
                        project_name = project.replace('_','-')
                        if obj_name.startswith('%s-%s'%(package_name,tt)) or obj_name.startswith('%s-tag-%s'%(package_name,tt)) \
                                or obj_name.startswith('%s-%s'%(project_name,tt)):
                            try:
                                ver = obj_name.split(tt)[-1].split('.')[0]
                                version = '%s%s'%(tt,ver)
                                versions.append(version)
                            except:
                                pass
                versions = list(set(versions))
                versions.sort(reverse=True)
                if len(versions) >15:
                    versions = versions[:15]
    except Exception as e:
        logging.error(e)
    finally:
        db_op.DB.session.remove()
        return jsonify({project:versions}) 
开发者ID:wylok,项目名称:sparrow,代码行数:34,代码来源:ajax_api.py

示例5: test_object_iterator

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def test_object_iterator(self):
        prefix = self.random_key('/')
        object_list = []
        dir_list = []

        # 准备文件
        for i in range(20):
            object_list.append(prefix + random_string(16))
            self.bucket.put_object(object_list[-1], random_bytes(10))

        # 准备目录
        for i in range(5):
            dir_list.append(prefix + random_string(5) + '/')
            self.bucket.put_object(dir_list[-1] + random_string(5), random_bytes(3))

        # 验证
        objects_got = []
        dirs_got = []
        for info in oss2.ObjectIterator(self.bucket, prefix, delimiter='/', max_keys=4):
            if info.is_prefix():
                dirs_got.append(info.key)
            else:
                objects_got.append(info.key)

                result = self.bucket.head_object(info.key)
                self.assertEqual(result.last_modified, info.last_modified)

        self.assertEqual(sorted(object_list), objects_got)
        self.assertEqual(sorted(dir_list), dirs_got)

        delete_keys(self.bucket, object_list) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:33,代码来源:test_iterator.py

示例6: test_object_iterator_chinese

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def test_object_iterator_chinese(self):
        for prefix in [self.random_key('中+文'), self.random_key(u'中+文')]:
            self.bucket.put_object(prefix, b'content of object')
            object_got = list(oss2.ObjectIterator(self.bucket, prefix=prefix, max_keys=1))[0].key
            self.assertEqual(to_string(prefix), object_got) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:7,代码来源:test_iterator.py

示例7: clean_and_delete_bucket

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def clean_and_delete_bucket(bucket):
    # check if bucket is in versioning status
    try:
        result = bucket.get_bucket_info()
        if result.versioning_status in [oss2.BUCKET_VERSIONING_ENABLE, oss2.BUCKET_VERSIONING_SUSPEND]:
            next_key_marker = None
            next_versionid_marker = None
            is_truncated = True
            while is_truncated is True:
                objects = bucket.list_object_versions(key_marker=next_key_marker, versionid_marker=next_versionid_marker)
                for obj in objects.versions:
                    bucket.delete_object(obj.key, params={'versionId': obj.versionid})
                for del_marker in objects.delete_marker:
                    bucket.delete_object(del_marker.key, params={'versionId': del_marker.versionid})
                is_truncated = objects.is_truncated
                if is_truncated:
                    next_key_marker = objects.next_key_marker
                    next_versionid_marker = objects.next_versionid_marker
    except:
        pass

    # list all upload_parts to delete
    up_iter = oss2.MultipartUploadIterator(bucket)
    for up in up_iter:
        bucket.abort_multipart_upload(up.key, up.upload_id)

    # list all objects to delete
    obj_iter = oss2.ObjectIterator(bucket)
    for obj in obj_iter:
        bucket.delete_object(obj.key)
    
    # list all live channels to delete
    for ch_iter in oss2.LiveChannelIterator(bucket):
        bucket.delete_live_channel(ch_iter.name)

    # delete_bucket
    bucket.delete_bucket() 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:39,代码来源:common.py

示例8: test_put_get_list_delete

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def test_put_get_list_delete(self):
        for key in ['中文!@#$%^&*()-=文件\x0C-1.txt', u'中文!@#$%^&*()-=文件\x0C-1.txt']:
            content = '中文内容'

            self.bucket.put_object(key, content)
            self.assertEqual(self.bucket.get_object(key).read(), to_bytes(content))

            self.assertTrue(to_string(key) in list(info.key for info in oss2.ObjectIterator(self.bucket, prefix='中文')))

            self.bucket.delete_object(key) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:12,代码来源:test_chinese.py

示例9: list_file

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import ObjectIterator [as 别名]
def list_file(self):
        # 遍历Bucket里所有文件
        for object_info in oss2.ObjectIterator(self.bucket):
            print(object_info.key) 
开发者ID:nickliqian,项目名称:darknet_captcha,代码行数:6,代码来源:upload2oss.py


注:本文中的oss2.ObjectIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。