Example #1
0
 def do_create(self, args):
     """Create new archive"""
     t0 = datetime.now()
     repository = self.open_repository(args.archive, exclusive=True)
     manifest, key = Manifest.load(repository)
     cache = Cache(repository, key, manifest, do_files=args.cache_files)
     archive = Archive(repository, key, manifest, args.archive.archive, cache=cache,
                       create=True, checkpoint_interval=args.checkpoint_interval,
                       numeric_owner=args.numeric_owner, progress=args.progress)
     # Add cache dir to inode_skip list
     skip_inodes = set()
     try:
         st = os.stat(get_cache_dir())
         skip_inodes.add((st.st_ino, st.st_dev))
     except IOError:
         pass
     # Add local repository dir to inode_skip list
     if not args.archive.host:
         try:
             st = os.stat(args.archive.path)
             skip_inodes.add((st.st_ino, st.st_dev))
         except IOError:
             pass
     for path in args.paths:
         if path == '-':  # stdin
             path = 'stdin'
             self.print_verbose(path)
             try:
                 archive.process_stdin(path, cache)
             except IOError as e:
                 self.print_error('%s: %s', path, e)
             continue
         path = os.path.normpath(path)
         if args.dontcross:
             try:
                 restrict_dev = os.lstat(path).st_dev
             except OSError as e:
                 self.print_error('%s: %s', path, e)
                 continue
         else:
             restrict_dev = None
         self._process(archive, cache, args.excludes, args.exclude_caches, skip_inodes, path, restrict_dev)
     archive.save(timestamp=args.timestamp)
     if args.progress:
         archive.stats.show_progress(final=True)
     if args.stats:
         t = datetime.now()
         diff = t - t0
         print('-' * 78)
         print('Archive name: %s' % args.archive.archive)
         print('Archive fingerprint: %s' % hexlify(archive.id).decode('ascii'))
         print('Start time: %s' % t0.strftime('%c'))
         print('End time: %s' % t.strftime('%c'))
         print('Duration: %s' % format_timedelta(diff))
         print('Number of files: %d' % archive.stats.nfiles)
         archive.stats.print_('This archive:', cache)
         print('-' * 78)
     return self.exit_code