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