added debug output into filter_path
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 22 Jun 2016 13:20:27 +0000 (15:20 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 09:32:53 +0000 (11:32 +0200)
deltatar/deltatar.py

index 5c3d9b5..2455be8 100644 (file)
@@ -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