]> arthur.barton.de Git - bup.git/blobdiff - cmd/drecurse-cmd.py
helpers: accommodate python 3 and enable tests
[bup.git] / cmd / drecurse-cmd.py
index 5be71b5d1fd82df72db1157ef8ec666417c948e4..a3a7d30aa4a368ce682bc55b83c55f0478bb84b2 100755 (executable)
@@ -1,6 +1,17 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+from __future__ import absolute_import, print_function
+from os.path import relpath
+import sys
+
 from bup import options, drecurse
-from bup.helpers import *
+from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors
+
 
 optspec = """
 bup drecurse <path>
@@ -8,6 +19,8 @@ bup drecurse <path>
 x,xdev,one-file-system   don't cross filesystem boundaries
 exclude= a path to exclude from the backup (can be used more than once)
 exclude-from= a file that contains exclude paths (can be used more than once)
+exclude-rx= skip paths matching the unanchored regex (may be repeated)
+exclude-rx-from= skip --exclude-rx patterns in file (may be repeated)
 q,quiet  don't actually print filenames
 profile  run under the python profiler
 """
@@ -17,9 +30,14 @@ o = options.Options(optspec)
 if len(extra) != 1:
     o.fatal("exactly one filename expected")
 
-excluded_paths = drecurse.parse_excludes(flags)
-
-it = drecurse.recursive_dirlist(extra, opt.xdev, excluded_paths)
+drecurse_top = extra[0]
+excluded_paths = parse_excludes(flags, o.fatal)
+if not drecurse_top.startswith('/'):
+    excluded_paths = [relpath(x) for x in excluded_paths]
+exclude_rxs = parse_rx_excludes(flags, o.fatal)
+it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
+                                excluded_paths=excluded_paths,
+                                exclude_rxs=exclude_rxs)
 if opt.profile:
     import cProfile
     def do_it():
@@ -32,7 +50,7 @@ else:
             pass
     else:
         for (name,st) in it:
-            print name
+            print(name)
 
 if saved_errors:
     log('WARNING: %d errors encountered.\n' % len(saved_errors))