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


Python Archive.iter_items方法代码示例

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


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

示例1: do_list

# 需要导入模块: from attic.archive import Archive [as 别名]
# 或者: from attic.archive.Archive import iter_items [as 别名]
 def do_list(self, args):
     """List archive or repository contents"""
     repository = self.open_repository(args.src)
     manifest, key = Manifest.load(repository)
     if args.src.archive:
         tmap = {1: 'p', 2: 'c', 4: 'd', 6: 'b', 0o10: '-', 0o12: 'l', 0o14: 's'}
         archive = Archive(repository, key, manifest, args.src.archive)
         for item in archive.iter_items():
             type = tmap.get(item[b'mode'] // 4096, '?')
             mode = format_file_mode(item[b'mode'])
             size = 0
             if type == '-':
                 try:
                     size = sum(size for _, size, _ in item[b'chunks'])
                 except KeyError:
                     pass
             mtime = format_time(datetime.fromtimestamp(bigint_to_int(item[b'mtime']) / 1e9))
             if b'source' in item:
                 if type == 'l':
                     extra = ' -> %s' % item[b'source']
                 else:
                     type = 'h'
                     extra = ' link to %s' % item[b'source']
             else:
                 extra = ''
             print('%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item[b'user'] or item[b'uid'],
                                               item[b'group'] or item[b'gid'], size, mtime,
                                               remove_surrogates(item[b'path']), extra))
     else:
         for archive in sorted(Archive.list_archives(repository, key, manifest), key=attrgetter('ts')):
             print(format_archive(archive))
     return self.exit_code
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-attic,代码行数:34,代码来源:archiver.py

示例2: do_extract

# 需要导入模块: from attic.archive import Archive [as 别名]
# 或者: from attic.archive.Archive import iter_items [as 别名]
    def do_extract(self, args):
        """Extract archive contents
        """
        repository = self.open_repository(args.archive)
        manifest, key = Manifest.load(repository)
        archive = Archive(repository, key, manifest, args.archive.archive,
                          numeric_owner=args.numeric_owner)
        patterns = adjust_patterns(args.paths, args.excludes)
        dirs = []
        for item, peek in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns)):
            while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
                archive.extract_item(dirs.pop(-1))
            self.print_verbose(remove_surrogates(item[b'path']))
            try:
                if stat.S_ISDIR(item[b'mode']):
                    dirs.append(item)
                    archive.extract_item(item, restore_attrs=False)
                else:
                    archive.extract_item(item, peek=peek)
            except IOError as e:
                self.print_error('%s: %s', remove_surrogates(item[b'path']), e)

        while dirs:
            archive.extract_item(dirs.pop(-1))
        return self.exit_code
开发者ID:Ernest0x,项目名称:attic,代码行数:27,代码来源:archiver.py

示例3: do_extract

# 需要导入模块: from attic.archive import Archive [as 别名]
# 或者: from attic.archive.Archive import iter_items [as 别名]
    def do_extract(self, args):
        """Extract archive contents"""
        # be restrictive when restoring files, restore permissions later
        if sys.getfilesystemencoding() == 'ascii':
            print('Warning: File system encoding is "ascii", extracting non-ascii filenames will not be supported.')
        os.umask(0o077)
        repository = self.open_repository(args.archive)
        manifest, key = Manifest.load(repository)
        archive = Archive(repository, key, manifest, args.archive.archive,
                          numeric_owner=args.numeric_owner)
        patterns = adjust_patterns(args.paths, args.excludes)
        dry_run = args.dry_run
        stdout = args.stdout
        sparse = args.sparse
        strip_components = args.strip_components
        dirs = []
        for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
            orig_path = item[b'path']
            if strip_components:
                item[b'path'] = os.sep.join(orig_path.split(os.sep)[strip_components:])
                if not item[b'path']:
                    continue
            if not args.dry_run:
                while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
                    archive.extract_item(dirs.pop(-1), stdout=stdout)
            self.print_verbose(remove_surrogates(orig_path))
            try:
                if dry_run:
                    archive.extract_item(item, dry_run=True)
                else:
                    if stat.S_ISDIR(item[b'mode']):
                        dirs.append(item)
                        archive.extract_item(item, restore_attrs=False)
                    else:
                        archive.extract_item(item, stdout=stdout, sparse=sparse)
            except IOError as e:
                self.print_error('%s: %s', remove_surrogates(orig_path), e)

        if not args.dry_run:
            while dirs:
                archive.extract_item(dirs.pop(-1))
        return self.exit_code
开发者ID:joolswills,项目名称:borg,代码行数:44,代码来源:archiver.py

示例4: do_verify

# 需要导入模块: from attic.archive import Archive [as 别名]
# 或者: from attic.archive.Archive import iter_items [as 别名]
    def do_verify(self, args):
        """Verify archive consistency
        """
        repository = self.open_repository(args.archive)
        manifest, key = Manifest.load(repository)
        archive = Archive(repository, key, manifest, args.archive.archive)
        patterns = adjust_patterns(args.paths, args.excludes)

        def start_cb(item):
            self.print_verbose('%s ...', remove_surrogates(item[b'path']), newline=False)

        def result_cb(item, success):
            if success:
                self.print_verbose('OK')
            else:
                self.print_verbose('ERROR')
                self.print_error('%s: verification failed' % remove_surrogates(item[b'path']))
        for item, peek in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns)):
            if stat.S_ISREG(item[b'mode']) and b'chunks' in item:
                archive.verify_file(item, start_cb, result_cb, peek=peek)
        return self.exit_code
开发者ID:Ernest0x,项目名称:attic,代码行数:23,代码来源:archiver.py

示例5: do_extract

# 需要导入模块: from attic.archive import Archive [as 别名]
# 或者: from attic.archive.Archive import iter_items [as 别名]
    def do_extract(self, args):
        """Extract archive contents"""
        repository = self.open_repository(args.archive)
        manifest, key = Manifest.load(repository)
        archive = Archive(repository, key, manifest, args.archive.archive,
                          numeric_owner=args.numeric_owner)
        patterns = adjust_patterns(args.paths, args.excludes)
        dry_run = args.dry_run
        strip_components = args.strip_components
        dirs = []
        for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
            orig_path = item[b'path']
            if strip_components:
                item[b'path'] = os.sep.join(orig_path.split(os.sep)[strip_components:])
                if not item[b'path']:
                    continue
            if not args.dry_run:
                while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
                    archive.extract_item(dirs.pop(-1))
            self.print_verbose(remove_surrogates(orig_path))
            try:
                if dry_run:
                    archive.extract_item(item, dry_run=True)
                else:
                    if stat.S_ISDIR(item[b'mode']):
                        dirs.append(item)
                        archive.extract_item(item, restore_attrs=False)
                    else:
                        archive.extract_item(item)
            except IOError as e:
                self.print_error('%s: %s', remove_surrogates(orig_path), e)

        if not args.dry_run:
            while dirs:
                archive.extract_item(dirs.pop(-1))
        return self.exit_code
开发者ID:copart,项目名称:attic,代码行数:38,代码来源:archiver.py


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