3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 # Copyright (C) 2010 Rob Browning
10 # This code is covered under the terms of the GNU Library General
11 # Public License as described in the bup LICENSE file.
13 # TODO: Add tar-like -C option.
16 from bup import metadata
17 from bup import options
18 from bup.helpers import handle_ctrl_c, log, saved_errors
22 if not name or name == '-':
24 return open(name, 'r')
27 def open_output(name):
28 if not name or name == '-':
30 return open(name, 'w')
34 bup meta --create [OPTION ...] <PATH ...>
35 bup meta --list [OPTION ...]
36 bup meta --extract [OPTION ...]
37 bup meta --start-extract [OPTION ...]
38 bup meta --finish-extract [OPTION ...]
39 bup meta --edit [OPTION ...] <PATH ...>
41 c,create write metadata for PATHs to stdout (or --file)
42 t,list display metadata
43 x,extract perform --start-extract followed by --finish-extract
44 start-extract build tree matching metadata provided on standard input (or --file)
45 finish-extract finish applying standard input (or --file) metadata to filesystem
46 edit alter metadata; write to stdout (or --file)
47 f,file= specify source or destination file
48 R,recurse recurse into subdirectories
49 xdev,one-file-system don't cross filesystem boundaries
50 numeric-ids apply numeric IDs (user, group, etc.) rather than names
51 symlinks handle symbolic links (default is true)
52 paths include paths in metadata (default is true)
53 set-uid= set metadata uid (via --edit)
54 set-gid= set metadata gid (via --edit)
55 set-user= set metadata user (via --edit)
56 unset-user remove metadata user (via --edit)
57 set-group= set metadata group (via --edit)
58 unset-group remove metadata group (via --edit)
59 v,verbose increase log output (can be used more than once)
60 q,quiet don't show progress meter
65 o = options.Options(optspec)
66 (opt, flags, remainder) = o.parse(['--paths', '--symlinks', '--recurse']
69 opt.verbose = opt.verbose or 0
70 opt.quiet = opt.quiet or 0
71 metadata.verbose = opt.verbose - opt.quiet
73 action_count = sum([bool(x) for x in [opt.create, opt.list, opt.extract,
74 opt.start_extract, opt.finish_extract,
77 o.fatal("bup: only one action permitted: --create --list --extract --edit")
79 o.fatal("bup: no action specified")
82 if len(remainder) < 1:
83 o.fatal("no paths specified for create")
84 output_file = open_output(opt.file)
85 metadata.save_tree(output_file,
88 write_paths=opt.paths,
89 save_symlinks=opt.symlinks,
92 if len(remainder) > 0:
93 o.fatal("cannot specify paths for --list")
94 src = open_input(opt.file)
95 metadata.display_archive(src)
96 elif opt.start_extract:
97 if len(remainder) > 0:
98 o.fatal("cannot specify paths for --start-extract")
99 src = open_input(opt.file)
100 metadata.start_extract(src, create_symlinks=opt.symlinks)
101 elif opt.finish_extract:
102 if len(remainder) > 0:
103 o.fatal("cannot specify paths for --finish-extract")
104 src = open_input(opt.file)
105 metadata.finish_extract(src, restore_numeric_ids=opt.numeric_ids)
107 if len(remainder) > 0:
108 o.fatal("cannot specify paths for --extract")
109 src = open_input(opt.file)
110 metadata.extract(src,
111 restore_numeric_ids=opt.numeric_ids,
112 create_symlinks=opt.symlinks)
114 if len(remainder) < 1:
115 o.fatal("no paths specified for edit")
116 output_file = open_output(opt.file)
118 unset_user = False # True if --unset-user was the last relevant option.
119 unset_group = False # True if --unset-group was the last relevant option.
121 if flag[0] == '--set-user':
123 elif flag[0] == '--unset-user':
125 elif flag[0] == '--set-group':
127 elif flag[0] == '--unset-group':
130 for path in remainder:
133 for m in metadata._ArchiveIterator(f):
134 if opt.set_uid is not None:
136 m.uid = int(opt.set_uid)
138 o.fatal("uid must be an integer")
140 if opt.set_gid is not None:
142 m.gid = int(opt.set_gid)
144 o.fatal("gid must be an integer")
148 elif opt.set_user is not None:
149 m.user = opt.set_user
153 elif opt.set_group is not None:
154 m.group = opt.set_group
162 log('WARNING: %d errors encountered.\n' % len(saved_errors))