# match mode
-NO_MATCH = False
-MATCH = True
+NO_MATCH = 0
+MATCH = 1
PARENT_MATCH = 2
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
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
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
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