~aaron-whitehouse/duplicity/bug_932482_trailing_slashes_and_wildcards_error

« back to all changes in this revision

Viewing changes to duplicity/selection.py

  • Committer: Kenneth Loafman
  • Date: 2015-01-29 13:44:20 UTC
  • mfrom: (1063.1.1 duplicity)
  • Revision ID: kenneth@loafman.com-20150129134420-lq4v3bprarcqoa8n
* Merged in lp:~angusgr/duplicity/exclude-older-than
  - Add "--exclude-older-than" commandline option, that allows you to only
    back up files with a modification date newer than a particular threshold.
* Additional pep8 cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
245
245
                    self.add_selection_func(self.other_filesystems_get_sf(0))
246
246
                elif opt == "--exclude-regexp":
247
247
                    self.add_selection_func(self.regexp_get_sf(arg, 0))
 
248
                elif opt == "--exclude-older-than":
 
249
                    self.add_selection_func(self.exclude_older_get_sf(arg))
248
250
                elif opt == "--include":
249
251
                    self.add_selection_func(self.glob_get_sf(arg, 1))
250
252
                elif opt == "--include-filelist":
644
646
        else:
645
647
            return exclude_sel_func
646
648
 
 
649
    def exclude_older_get_sf(self, date):
 
650
        """Return selection function based on files older than modification date """
 
651
 
 
652
        def sel_func(path):
 
653
            if not path.isreg():
 
654
                return None
 
655
            try:
 
656
                if os.path.getmtime(path.name) < date:
 
657
                    return 0
 
658
            except OSError, e:
 
659
                pass  # this is probably only on a race condition of file being deleted
 
660
            return None
 
661
 
 
662
        sel_func.exclude = True
 
663
        sel_func.name = "Select older than %s" % (date,)
 
664
        return sel_func
 
665
 
 
666
 
647
667
    def glob_get_prefix_res(self, glob_str):
648
668
        """Return list of regexps equivalent to prefixes of glob_str"""
649
669
        glob_parts = glob_str.split("/")