]> arthur.barton.de Git - bup.git/blob - lib/bup/cmd/drecurse.py
chmod -x lib/bup/cmd/*.py
[bup.git] / lib / bup / cmd / drecurse.py
1
2 from __future__ import absolute_import, print_function
3 from os.path import relpath
4 import sys
5
6 from bup import options, drecurse
7 from bup.compat import argv_bytes
8 from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors
9 from bup.io import byte_stream
10
11
12 optspec = """
13 bup drecurse <path>
14 --
15 x,xdev,one-file-system   don't cross filesystem boundaries
16 exclude= a path to exclude from the backup (can be used more than once)
17 exclude-from= a file that contains exclude paths (can be used more than once)
18 exclude-rx= skip paths matching the unanchored regex (may be repeated)
19 exclude-rx-from= skip --exclude-rx patterns in file (may be repeated)
20 q,quiet  don't actually print filenames
21 profile  run under the python profiler
22 """
23
24 def main(argv):
25     o = options.Options(optspec)
26     opt, flags, extra = o.parse_bytes(argv[1:])
27
28     if len(extra) != 1:
29         o.fatal("exactly one filename expected")
30
31     drecurse_top = argv_bytes(extra[0])
32     excluded_paths = parse_excludes(flags, o.fatal)
33     if not drecurse_top.startswith(b'/'):
34         excluded_paths = [relpath(x) for x in excluded_paths]
35     exclude_rxs = parse_rx_excludes(flags, o.fatal)
36     it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
37                                     excluded_paths=excluded_paths,
38                                     exclude_rxs=exclude_rxs)
39     if opt.profile:
40         import cProfile
41         def do_it():
42             for i in it:
43                 pass
44         cProfile.run('do_it()')
45     else:
46         if opt.quiet:
47             for i in it:
48                 pass
49         else:
50             sys.stdout.flush()
51             out = byte_stream(sys.stdout)
52             for (name,st) in it:
53                 out.write(name + b'\n')
54
55     if saved_errors:
56         log('WARNING: %d errors encountered.\n' % len(saved_errors))
57         sys.exit(1)