]> arthur.barton.de Git - bup.git/blob - cmd/drecurse-cmd.py
Fix drecurse relative --excludes, quash duplicates, and add tests.
[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 q,quiet  don't actually print filenames
14 profile  run under the python profiler
15 """
16 o = options.Options(optspec)
17 (opt, flags, extra) = o.parse(sys.argv[1:])
18
19 if len(extra) != 1:
20     o.fatal("exactly one filename expected")
21
22 drecurse_top = extra[0]
23 excluded_paths = parse_excludes(flags, o.fatal)
24 if not drecurse_top.startswith('/'):
25     excluded_paths = [relpath(x) for x in excluded_paths]
26 it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
27                                 excluded_paths=excluded_paths)
28 if opt.profile:
29     import cProfile
30     def do_it():
31         for i in it:
32             pass
33     cProfile.run('do_it()')
34 else:
35     if opt.quiet:
36         for i in it:
37             pass
38     else:
39         for (name,st) in it:
40             print name
41
42 if saved_errors:
43     log('WARNING: %d errors encountered.\n' % len(saved_errors))
44     sys.exit(1)