]> arthur.barton.de Git - bup.git/blob - cmd/drecurse-cmd.py
611bfdbb3e89bdc3d93d9900fc3b38fc5cb6343d
[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 from bup import options, drecurse
10 from bup.helpers import *
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 o = options.Options(optspec)
24 (opt, flags, extra) = o.parse(sys.argv[1:])
25
26 if len(extra) != 1:
27     o.fatal("exactly one filename expected")
28
29 drecurse_top = extra[0]
30 excluded_paths = parse_excludes(flags, o.fatal)
31 if not drecurse_top.startswith('/'):
32     excluded_paths = [relpath(x) for x in excluded_paths]
33 exclude_rxs = parse_rx_excludes(flags, o.fatal)
34 it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
35                                 excluded_paths=excluded_paths,
36                                 exclude_rxs=exclude_rxs)
37 if opt.profile:
38     import cProfile
39     def do_it():
40         for i in it:
41             pass
42     cProfile.run('do_it()')
43 else:
44     if opt.quiet:
45         for i in it:
46             pass
47     else:
48         for (name,st) in it:
49             print name
50
51 if saved_errors:
52     log('WARNING: %d errors encountered.\n' % len(saved_errors))
53     sys.exit(1)