Example #1
0
 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(item[b'mtime'] / 10**9))
             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('%-20s %s' % (archive.metadata[b'name'], to_localtime(archive.ts).strftime('%c')))
     return self.exit_code
 def do_info(self, args):
     """Show archive details such as disk space used"""
     repository = self.open_repository(args.archive)
     manifest, key = Manifest.load(repository)
     cache = Cache(repository, key, manifest)
     archive = Archive(repository, key, manifest, args.archive.archive, cache=cache)
     stats = archive.calc_stats(cache)
     print('Name:', archive.name)
     print('Fingerprint: %s' % hexlify(archive.id).decode('ascii'))
     print('Hostname:', archive.metadata[b'hostname'])
     print('Username:'******'username'])
     print('Time: %s' % to_localtime(archive.ts).strftime('%c'))
     print('Command line:', remove_surrogates(' '.join(archive.metadata[b'cmdline'])))
     print('Number of files: %d' % stats.nfiles)
     stats.print_('This archive:', cache)
     return self.exit_code
Example #3
0
 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(item[b'mtime'] / 10**9))
             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('%-20s %s' % (archive.metadata[b'name'],
                                 to_localtime(archive.ts).strftime('%c')))
     return self.exit_code
Example #4
0
 def do_info(self, args):
     """Show archive details such as disk space used"""
     repository = self.open_repository(args.archive)
     manifest, key = Manifest.load(repository)
     cache = Cache(repository, key, manifest)
     archive = Archive(repository,
                       key,
                       manifest,
                       args.archive.archive,
                       cache=cache)
     stats = archive.calc_stats(cache)
     print('Name:', archive.name)
     print('Fingerprint: %s' % hexlify(archive.id).decode('ascii'))
     print('Hostname:', archive.metadata[b'hostname'])
     print('Username:'******'username'])
     print('Time: %s' % to_localtime(archive.ts).strftime('%c'))
     print('Command line:',
           remove_surrogates(' '.join(archive.metadata[b'cmdline'])))
     print('Number of files: %d' % stats.nfiles)
     stats.print_('This archive:', cache)
     return self.exit_code