]> arthur.barton.de Git - bup.git/blob - lib/cmd/drecurse-cmd.py
ftp-cmd: copy to bup.cmd.ftp
[bup.git] / lib / cmd / drecurse-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
5 arg_i=1
6 for arg in "$@"; do
7     export "BUP_ARGV_${arg_i}"="$arg"
8     shift
9     arg_i=$((arg_i + 1))
10 done
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
14 """
15 # end of bup preamble
16
17 from __future__ import absolute_import, print_function
18
19 # Intentionally replace the dirname "$0" that python prepends
20 import os, sys
21 sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/..'
22
23 from os.path import relpath
24
25 from bup import compat, options, drecurse
26 from bup.compat import argv_bytes
27 from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors
28 from bup.io import byte_stream
29
30
31 optspec = """
32 bup drecurse <path>
33 --
34 x,xdev,one-file-system   don't cross filesystem boundaries
35 exclude= a path to exclude from the backup (can be used more than once)
36 exclude-from= a file that contains exclude paths (can be used more than once)
37 exclude-rx= skip paths matching the unanchored regex (may be repeated)
38 exclude-rx-from= skip --exclude-rx patterns in file (may be repeated)
39 q,quiet  don't actually print filenames
40 profile  run under the python profiler
41 """
42 o = options.Options(optspec)
43 opt, flags, extra = o.parse(compat.argv[1:])
44
45 if len(extra) != 1:
46     o.fatal("exactly one filename expected")
47
48 drecurse_top = argv_bytes(extra[0])
49 excluded_paths = parse_excludes(flags, o.fatal)
50 if not drecurse_top.startswith(b'/'):
51     excluded_paths = [relpath(x) for x in excluded_paths]
52 exclude_rxs = parse_rx_excludes(flags, o.fatal)
53 it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
54                                 excluded_paths=excluded_paths,
55                                 exclude_rxs=exclude_rxs)
56 if opt.profile:
57     import cProfile
58     def do_it():
59         for i in it:
60             pass
61     cProfile.run('do_it()')
62 else:
63     if opt.quiet:
64         for i in it:
65             pass
66     else:
67         sys.stdout.flush()
68         out = byte_stream(sys.stdout)
69         for (name,st) in it:
70             out.write(name + b'\n')
71
72 if saved_errors:
73     log('WARNING: %d errors encountered.\n' % len(saved_errors))
74     sys.exit(1)