瀏覽代碼

minor changes due to TWs review

Alexander 'Leo' Bergolth 8 年之前
父節點
當前提交
ead93b2e58
共有 3 個文件被更改,包括 29 次插入39 次删除
  1. 14 22
      borg/archiver.py
  2. 12 14
      borg/helpers.py
  3. 3 3
      borg/testsuite/helpers.py

+ 14 - 22
borg/archiver.py

@@ -894,7 +894,7 @@ class Archiver:
 
     helptext = collections.OrderedDict()
     helptext['patterns'] = textwrap.dedent('''
-        File patterns support four separate styles, fnmatch, shell, regular
+        File patterns support four separate styles: fnmatch, shell, regular
         expressions and path prefixes. By default, fnmatch is used for
         `--exclude` patterns and shell-style is used for `--pattern`. If followed
         by a colon (':') the first two characters of a pattern are used as a
@@ -983,26 +983,24 @@ class Archiver:
             EOF
             $ borg create --exclude-from exclude.txt backup /
 
-            # exclude the contents of /data/docs/ but not /data/docs/pdf
-            $ borg create -e +/data/docs/pdf -e /data/docs/ backup /
-            # equivalent:
-            $ borg create -e +pm:/data/docs/pdf -e -pm:/data/docs/ backup /
 
-
-        A more general way to define filename matching patterns may be passed via
-        `--pattern` and `--patterns-from`. Using these options, you may specify the
-        backup roots (starting points) and patterns for inclusion/exclusion. A
+        A more general and easier to use way to define filename matching patterns exists
+        with the `--pattern` and `--patterns-from` options. Using these, you may specify
+        the backup roots (starting points) and patterns for inclusion/exclusion. A
         root path starts with the prefix `R`, followed by a path (a plain path, not a
-        file pattern). An include rule is specified by `+` followed by a pattern.
-        Exclude rules start with a `-`.
-        Inclusion patterns are useful to e.g. exclude the contents of a directory
-        except for some important files in this directory. The first matching pattern
-        is used so if an include pattern matches before an exclude pattern, the file
-        is backed up.
+        file pattern). An include rule starts with the prefix +, an exclude rule starts
+        with the prefix -, both followed by a pattern.
+        Inclusion patterns are useful to include pathes that are contained in an excluded
+        path. The first matching pattern is used so if an include pattern matches before
+        an exclude pattern, the file is backed up.
 
         Note that the default pattern style for `--pattern` and `--patterns-from` is
         shell style (`sh:`), so those patterns behave like rsync include/exclude patterns.
 
+        Patterns (`--pattern`) and excludes (`--exclude`) from the command line are
+        considered first (in the order of appearance). Then patterns from `--pattern-from`
+        are added. Exclusion patterns from `--exclude-from` files are appended last.
+
         An example `--patterns-from` file could look like that::
 
             R /
@@ -1014,13 +1012,7 @@ class Archiver:
             # include susans home
             + /home/susan
             # don't backup the other home directories
-            - /home/*
-
-        Patterns (`--pattern`) and excludes (`--exclude`) from the command line are
-        considered first (in the order of appearance). Then patterns from `--pattern-from`
-        are added. Exclusion patterns from `--exclude-from` files are appended last.
-
-\n\n''')
+            - /home/*\n\n''')
     helptext['placeholders'] = textwrap.dedent('''
         Repository (or Archive) URLs, --prefix and --remote-path values support these
         placeholders:

+ 12 - 14
borg/helpers.py

@@ -322,23 +322,22 @@ def load_patterns(fh):
     """
     patternlines = (line for line in (i.strip() for i in fh) if not line.startswith('#'))
     roots = []
-    inclexclpatterns = []
+    inclexcl_patterns = []
     for patternline in patternlines:
         pattern = parse_inclexcl_pattern(patternline)
-        if pattern:
-            if pattern.ptype is RootPath:
-                roots.append(pattern.pattern)
-            else:
-                inclexclpatterns.append(pattern)
-    return roots, inclexclpatterns
+        if pattern.ptype is RootPath:
+            roots.append(pattern.pattern)
+        else:
+            inclexcl_patterns.append(pattern)
+    return roots, inclexcl_patterns
 
 
 def update_patterns(args):
     """Merge patterns from exclude- and pattern-files with those on command line."""
     for file in args.pattern_files:
-        roots, inclexclpatterns = load_patterns(file)
+        roots, inclexcl_patterns = load_patterns(file)
         args.paths += roots
-        args.patterns += inclexclpatterns
+        args.patterns += inclexcl_patterns
         file.close()
     for file in args.exclude_files:
         args.patterns += load_excludes(file)
@@ -351,11 +350,10 @@ class ArgparsePatternAction(argparse.Action):
 
     def __call__(self, parser, args, values, option_string=None):
         pattern = parse_inclexcl_pattern(values[0])
-        if pattern:
-            if pattern.ptype is RootPath:
-                args.paths.append(pattern.pattern)
-            else:
-                args.patterns.append(pattern)
+        if pattern.ptype is RootPath:
+            args.paths.append(pattern.pattern)
+        else:
+            args.patterns.append(pattern)
 
 
 class PatternMatcher:

+ 3 - 3
borg/testsuite/helpers.py

@@ -464,7 +464,7 @@ def test_load_patterns_from_file(tmpdir, lines, expected_roots, expected_numpatt
     def evaluate(filename):
         roots, inclexclpatterns = load_patterns(open(filename, "rt"))
         return roots, len(inclexclpatterns)
-    patternfile = tmpdir.join("exclude.txt")
+    patternfile = tmpdir.join("patterns.txt")
 
     with patternfile.open("wt") as fh:
         fh.write("\n".join(lines))
@@ -479,7 +479,7 @@ def test_load_patterns_from_file(tmpdir, lines, expected_roots, expected_numpatt
     (["/data"]),    # need a pattern type prefix
 ])
 def test_load_invalid_patterns_from_file(tmpdir, lines):
-    patternfile = tmpdir.join("exclude.txt")
+    patternfile = tmpdir.join("patterns.txt")
     with patternfile.open("wt") as fh:
         fh.write("\n".join(lines))
     filename = str(patternfile)
@@ -525,7 +525,7 @@ def test_inclexcl_patterns_from_file(tmpdir, lines, expected):
         matcher.add_inclexcl(inclexclpatterns)
         return [path for path in files if matcher.match(path)]
 
-    patternfile = tmpdir.join("exclude.txt")
+    patternfile = tmpdir.join("patterns.txt")
 
     with patternfile.open("wt") as fh:
         fh.write("\n".join(lines))