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