3 # Copyright (C) 2010 Rob Browning
5 # This code is covered under the terms of the GNU Library General
6 # Public License as described in the bup LICENSE file.
8 # TODO: Add tar-like -C option.
9 # TODO: Add tar-like -v support to --list.
12 from bup import metadata
13 from bup import options
14 from bup.helpers import handle_ctrl_c, log, saved_errors
18 if not name or name == '-':
20 return open(name, 'r')
23 def open_output(name):
24 if not name or name == '-':
26 return open(name, 'w')
30 bup meta --create [OPTION ...] <PATH ...>
31 bup meta --extract [OPTION ...]
32 bup meta --start-extract [OPTION ...]
33 bup meta --finish-extract [OPTION ...]
35 c,create write metadata for PATHs to stdout (or --file)
36 t,list display metadata
37 x,extract perform --start-extract followed by --finish-extract
38 start-extract build tree matching metadata provided on standard input (or --file)
39 finish-extract finish applying standard input (or --file) metadata to filesystem
40 f,file= specify source or destination file
41 R,recurse recurse into subdirectories
42 xdev,one-file-system don't cross filesystem boundaries
43 numeric-ids apply numeric IDs (user, group, etc.), not names, during restore
44 symlinks handle symbolic links (default is true)
45 paths include paths in metadata (default is true)
46 v,verbose increase log output (can be used more than once)
47 q,quiet don't show progress meter
52 o = options.Options(optspec)
53 (opt, flags, remainder) = o.parse(['--paths', '--symlinks'] + sys.argv[1:])
55 opt.verbose = opt.verbose or 0
56 opt.quiet = opt.quiet or 0
57 metadata.verbose = opt.verbose - opt.quiet
59 action_count = sum([bool(x) for x in [opt.create, opt.list, opt.extract,
60 opt.start_extract, opt.finish_extract]])
62 o.fatal("bup: only one action permitted: --create --list --extract")
64 o.fatal("bup: no action specified")
67 if len(remainder) < 1:
68 o.fatal("no paths specified for create")
69 output_file = open_output(opt.file)
70 metadata.save_tree(output_file,
73 write_paths=opt.paths,
74 save_symlinks=opt.symlinks,
77 if len(remainder) > 0:
78 o.fatal("cannot specify paths for --list")
79 src = open_input(opt.file)
80 metadata.display_archive(src)
81 elif opt.start_extract:
82 if len(remainder) > 0:
83 o.fatal("cannot specify paths for --start-extract")
84 src = open_input(opt.file)
85 metadata.start_extract(src, create_symlinks=opt.symlinks)
86 elif opt.finish_extract:
87 if len(remainder) > 0:
88 o.fatal("cannot specify paths for --finish-extract")
89 src = open_input(opt.file)
90 metadata.finish_extract(src, restore_numeric_ids=opt.numeric_ids)
92 if len(remainder) > 0:
93 o.fatal("cannot specify paths for --extract")
94 src = open_input(opt.file)
96 restore_numeric_ids=opt.numeric_ids,
97 create_symlinks=opt.symlinks)
100 log('WARNING: %d errors encountered.\n' % len(saved_errors))