]> arthur.barton.de Git - bup.git/commitdiff
Move parse_excludes to helpers and rework it a bit.
authorRob Browning <rlb@defaultvalue.org>
Fri, 8 Mar 2013 00:07:30 +0000 (18:07 -0600)
committerRob Browning <rlb@defaultvalue.org>
Fri, 8 Mar 2013 00:19:26 +0000 (18:19 -0600)
Don't use f before it's initialized.

Narrow the catch to open(), and only catch IOException.

Call Options.fatal() when there's an error (as does
helpers.parse_date_or_fatal()).

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
cmd/drecurse-cmd.py
cmd/index-cmd.py
lib/bup/drecurse.py
lib/bup/helpers.py
t/test.sh

index f80418592bc0c3f10343551f2467b87870ee3030..218b2ef077fee395809e8a3ff96f2d729e9fa9c3 100755 (executable)
@@ -17,7 +17,7 @@ o = options.Options(optspec)
 if len(extra) != 1:
     o.fatal("exactly one filename expected")
 
-excluded_paths = drecurse.parse_excludes(flags)
+excluded_paths = parse_excludes(flags, o.fatal)
 
 it = drecurse.recursive_dirlist(extra, opt.xdev, excluded_paths=excluded_paths)
 if opt.profile:
index fd3794108daa368864d95f49ce6001b8a7e4e806..5a8913d378733d32435c57c8708031891067c089 100755 (executable)
@@ -222,8 +222,7 @@ if opt.clear:
     log('clear: clearing index.\n')
     clear_index(indexfile)
 
-excluded_paths = drecurse.parse_excludes(flags)
-
+excluded_paths = parse_excludes(flags, o.fatal)
 paths = index.reduce_paths(extra)
 
 if opt.update:
index 866045ff680a313373d9e67d16a1756876412156..2f4f286e984c4fc6c377446c91451866c764fde4 100644 (file)
@@ -116,25 +116,3 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
         except:
             pass
         raise
-
-def parse_excludes(flags):
-    excluded_paths = []
-
-    for flag in flags:
-        (option, parameter) = flag
-        if option == '--exclude':
-            excluded_paths.append(realpath(parameter))
-
-        if option == '--exclude-from':
-            try:
-                try:
-                    f = open(realpath(parameter))
-                    for exclude_path in f.readlines():
-                        excluded_paths.append(realpath(exclude_path.strip()))
-                except Error, e:
-                    log("warning: couldn't read %s\n" % parameter)
-            finally:
-                f.close()
-
-    return excluded_paths
-
index d3eea3777676294a04c25e57e5ae0503ecd2919b..ca9358aae518e14711577b9b0f52ab40657e2896 100644 (file)
@@ -710,6 +710,24 @@ def parse_date_or_fatal(str, fatal):
         return date
 
 
+def parse_excludes(options, fatal):
+    """Traverse the options and extract all excludes, or call Option.fatal()."""
+    excluded_paths = []
+
+    for flag in options:
+        (option, parameter) = flag
+        if option == '--exclude':
+            excluded_paths.append(realpath(parameter))
+        elif option == '--exclude-from':
+            try:
+                f = open(realpath(parameter))
+            except IOError, e:
+                raise fatal("couldn't read %s" % parameter)
+            for exclude_path in f.readlines():
+                excluded_paths.append(realpath(exclude_path.strip()))
+    return excluded_paths
+
+
 # FIXME: Carefully consider the use of functions (os.path.*, etc.)
 # that resolve against the current filesystem in the strip/graft
 # functions for example, but elsewhere as well.  I suspect bup's not
index 797291b2a83103cf0ca0d504d4407bca81d377c5..d93671ca864de2980d2599225cdaecbbfbe43a7c 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -20,6 +20,7 @@ WVSTART "index"
 D=bupdata.tmp
 rm -rf $D
 mkdir $D
+WVFAIL bup index --exclude-from $D/cannot-exist $D
 WVPASSEQ "$(bup index --check -p)" ""
 WVPASSEQ "$(bup index --check -p $D)" ""
 WVFAIL [ -e $D.fake ]