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