]> arthur.barton.de Git - bup.git/commitdiff
Add index option "--exclude-rx-from FILE".
authorThomas Klausner <tk@giga.or.at>
Fri, 20 Dec 2013 16:53:51 +0000 (17:53 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sat, 21 Dec 2013 01:11:57 +0000 (19:11 -0600)
Signed-off-by: Thomas Klausner <tk@giga.or.at>
[rlb@defaultvalue.org: adjust commit message; change "path" to
 "pattern" in bup-index.md description; adjust bup-index.md text;
 adjust optspec text.]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Documentation/bup-index.md
cmd/index-cmd.py
lib/bup/helpers.py

index c9621bd3d4a68be545215799dc9c9ed392a0b487..a5404448c8b321fbe8055f56e6d49715fd17e673 100644 (file)
@@ -10,7 +10,8 @@ bup-index - print and/or update the bup filesystem index
 
 bup index \<-p|-m|-s|-u\> [-H] [-l] [-x] [\--fake-valid] [\--no-check-device]
 [\--fake-invalid] [\--check] [\--clear] [-f *indexfile*] [\--exclude *path*]
-[\--exclude-from *filename*] [\--exclude-rx *pattern*] [-v] \<filenames...\>
+[\--exclude-from *filename*] [\--exclude-rx *pattern*]
+[\--exclude-rx-from *filename*] [-v] \<filenames...\>
 
 # DESCRIPTION
 
@@ -147,11 +148,11 @@ does, due to the accommodations described above.
 
 \--exclude=*path*
 :   exclude *path* from the backup; bup will not expand *path* in any
-    way (can be used more than once).
+    way (may be repeated).
 
 \--exclude-from=*filename*
-:   read --exclude paths from *filename*, one path per-line (can be
-    used more than once).
+:   read --exclude paths from *filename*, one path per-line (may be
+    repeated).
 
 \--exclude-rx=*pattern*
 :   exclude any path matching *pattern*, which must be a Python regular
@@ -159,7 +160,7 @@ does, due to the accommodations described above.
     will be compared against the full path, without anchoring, so
     "x/y" will match "ox/yard" or "box/yards".  To exclude the
     contents of /tmp, but not the directory itself, use
-    "^/tmp/.". (can be specified more than once)
+    "^/tmp/.". (may be repeated)
 
     Examples:
 
@@ -168,6 +169,10 @@ does, due to the accommodations described above.
       * '/foo/.' - exclude the content of any directory named foo
       * '^/tmp/.' - exclude root-level /tmp's content, but not /tmp itself
 
+\--exclude-rx-from=*filename*
+:   read --exclude-rx patterns from *filename*, one pattern per-line
+    (may be repeated).
+
 \--no-check-device
 :   don't mark a an entry invalid if the device number (stat(2)
     st_dev) changes.  This can be useful when indexing remote,
index 7bf526443f3acb65f515b873c42b5c747beaa221..59ec113517b10078a753226210aacc16e0b0deee 100755 (executable)
@@ -194,9 +194,10 @@ no-check-device don't invalidate an entry if the containing device changes
 fake-valid mark all index entries as up-to-date even if they aren't
 fake-invalid mark all index entries as invalid
 f,indexfile=  the name of the index file (normally BUP_DIR/bupindex)
-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 that match the unanchored regular expression
+exclude= a path to exclude from the backup (may be repeated)
+exclude-from= skip --exclude paths in file (may be repeated)
+exclude-rx= skip paths matching the unanchored regex (may be repeated)
+exclude-rx-from= skip --exclude-rx patterns in file (may be repeated)
 v,verbose  increase log output (can be used more than once)
 x,xdev,one-file-system  don't cross filesystem boundaries
 """
index 19035d1d1c3ed74f5b6b78fb0a404e17ca8ed158..c090bc0ab09e0f13a68019b32b88ba3cf5a957bf 100644 (file)
@@ -748,13 +748,27 @@ def parse_excludes(options, fatal):
 def parse_rx_excludes(options, fatal):
     """Traverse the options and extract all rx excludes, or call
     Option.fatal()."""
-    rxs = [v for f, v in options if f == '--exclude-rx']
-    for i in range(len(rxs)):
-        try:
-            rxs[i] = re.compile(rxs[i])
-        except re.error, ex:
-            o.fatal('invalid --exclude-rx pattern (%s):' % (ex, rxs[i]))
-    return rxs
+    excluded_patterns = []
+
+    for flag in options:
+        (option, parameter) = flag
+        if option == '--exclude-rx':
+            try:
+                excluded_patterns.append(re.compile(parameter))
+            except re.error, ex:
+                fatal('invalid --exclude-rx pattern (%s): %s' % (parameter, ex))
+        elif option == '--exclude-rx-from':
+            try:
+                f = open(realpath(parameter))
+            except IOError, e:
+                raise fatal("couldn't read %s" % parameter)
+            for pattern in f.readlines():
+                spattern = pattern.rstrip('\n')
+                try:
+                    excluded_patterns.append(re.compile(spattern))
+                except re.error, ex:
+                    fatal('invalid --exclude-rx pattern (%s): %s' % (spattern, ex))
+    return excluded_patterns
 
 
 def should_rx_exclude_path(path, exclude_rxs):