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