~krissn/duplicity/xattr-selection-support

« back to all changes in this revision

Viewing changes to duplicity/selection.py

  • Committer: Krzysztof Nowicki
  • Date: 2013-10-14 11:21:33 UTC
  • Revision ID: krzysztof.nowicki@s3group.com-20131014112133-kzsdgjrzx7w2cl20
Add possibility to include/exclude files based on presence of a given extended attribute.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import re #@UnusedImport
24
24
import stat #@UnusedImport
25
25
import sys
 
26
import xattr
26
27
 
27
28
from duplicity.path import * #@UnusedWildImport
28
29
from duplicity import log #@Reimport
254
255
                    filelists_index += 1
255
256
                elif opt == "--include-regexp":
256
257
                    self.add_selection_func(self.regexp_get_sf(arg, 1))
 
258
                elif opt == "--exclude-xattr":
 
259
                    self.add_selection_func(self.xattr_get_sf(arg, 0))
 
260
                elif opt == "--include-xattr":
 
261
                    self.add_selection_func(self.xattr_get_sf(arg, 1))
257
262
                else:
258
263
                    assert 0, "Bad selection option %s" % opt
259
264
        except SelectError, e:
618
623
        else:
619
624
            return exclude_sel_func
620
625
 
 
626
    def xattr_get_sf(self, xattr_name, include):
 
627
        """Return a selection function to include/exclude files based on presence of
 
628
           an extended attribute"""
 
629
 
 
630
        def sel_func(path):
 
631
            try:
 
632
                xattr.get(path.name, xattr_name)
 
633
                return include
 
634
            except:
 
635
                print(sys.exc_info())
 
636
                return None
 
637
 
 
638
        sel_func.exclude = not include
 
639
        sel_func.name = "Include/exclude files based on extended attributes"
 
640
        return sel_func
 
641
 
621
642
    def glob_get_prefix_res(self, glob_str):
622
643
        """Return list of regexps equivalent to prefixes of glob_str"""
623
644
        glob_parts = glob_str.split("/")