From 28e41fe2fba0cb15cefbf281521eeb16ac696cb9 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Wed, 22 Jun 2016 15:20:27 +0200 Subject: [PATCH] added debug output into filter_path --- deltatar/deltatar.py | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 5c3d9b5..2455be8 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -41,8 +41,8 @@ logging.getLogger("deltatar.DeltaTar").addHandler(NullHandler()) # match mode -NO_MATCH = False -MATCH = True +NO_MATCH = 0 +MATCH = 1 PARENT_MATCH = 2 class DeltaTar(object): @@ -196,9 +196,8 @@ class DeltaTar(object): self.excluded_files = excluded_files self.included_files = included_files self.filter_func = filter_func - self.logger = logging.getLogger('deltatar.DeltaTar') if logger: - self.logger.addHandler(logger) + self.logger = logger self.mode = mode self.password = password @@ -295,18 +294,24 @@ class DeltaTar(object): if isinstance(i, str): # if the string matches, then continue if i == path: + self.logger.debug('filtering {!r}: == {}' + .format(path, i)) match = MATCH break # if the string ends with / it's a directory, and if the # path is contained in it, it is included if i.endswith('/') and path.startswith(i): + self.logger.debug('filtering {!r}: startswith({!r})' + .format(path, i)) match = MATCH break # if the string doesn't end with /, add it and do the same # check elif path.startswith(i + '/'): + self.logger.debug('filtering {!r}: startswith({!r} +/)' + .format(path, i)) match = MATCH break @@ -317,18 +322,25 @@ class DeltaTar(object): dir_path += '/' if i.startswith(dir_path): + self.logger.debug('filtering {!r}: is parent of {}' + .format(path, i)) match = PARENT_MATCH # if it's a reg exp, then we just check if it matches elif isinstance(i, re._pattern_type): if i.match(path): + self.logger.debug('filtering {!r}: matches regexp {}' + .format(path, i)) match = MATCH break else: self.logger.warn('Invalid pattern in included_files: %s' % str(i)) if match == NO_MATCH: + self.logger.debug('filtering {!r}: no match'.format(path)) return NO_MATCH + else: + self.logger.debug('filtering {!r}: everything included'.format(path)) # when a directory is in PARENT_MATCH, it doesn't matter if it's # excluded. It's subfiles will be excluded, but the directory itself @@ -339,27 +351,34 @@ class DeltaTar(object): if isinstance(e, str): # if the string matches, then exclude if e == path: + self.logger.debug('filtering {!r}: excluded'.format(path)) return NO_MATCH # if the string ends with / it's a directory, and if the # path starts with the directory, then exclude if e.endswith('/') and path.startswith(e): + self.logger.debug('filtering {!r}: excluded'.format(path)) return NO_MATCH # if the string doesn't end with /, do the same check with # the slash added elif path.startswith(e + '/'): + self.logger.debug('filtering {!r}: excluded'.format(path)) return NO_MATCH # if it's a reg exp, then we just check if it matches elif isinstance(e, re._pattern_type): if e.match(path): + self.logger.debug('filtering {!r}: excluded'.format(path)) return NO_MATCH else: self.logger.warn('Invalid pattern in excluded_files: %s' % str(e)) if self.filter_func: - return self.filter_func(path) + result = self.filter_func(path) + self.logger.debug('filtering {!r}: custom filter returns {}' + .format(path, result)) + return result return match -- 1.7.1