diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 31f43e5..f5a65cf 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -139,7 +139,9 @@ def _dotfile_compare(opts, dotfile, tmp): ignores = patch_ignores(ignores, dotfile.dst, debug=opts.debug) insttmp = None - if dotfile.template and Templategen.is_template(src, ignore=ignores): + if dotfile.template and Templategen.is_template(src, + ignore=ignores, + debug=opts.debug): # install dotfile to temporary dir for compare ret, err, insttmp = inst.install_to_temp(templ, tmp, src, dotfile.dst, is_template=True, diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 8b35e07..b5ca7f9 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -27,6 +27,7 @@ VAR_START = '{{@@' VAR_END = '@@}}' COMMENT_START = '{#@@' COMMENT_END = '@@#}' +LOG = Logger() class Templategen: @@ -215,26 +216,34 @@ class Templategen: return data.decode('utf-8', 'replace') @staticmethod - def is_template(path, ignore=None): + def is_template(path, ignore=None, debug=False): """recursively check if any file is a template within path""" + if debug: + LOG.dbg('is template: {}'.format(path), force=True) path = os.path.expanduser(path) - if utils.must_ignore([path], ignore, debug=False): - return False if not os.path.exists(path): + # does not exist return False + + if utils.must_ignore([path], ignore, debug=debug): + # must be ignored + return False + if os.path.isfile(path): # is file - return Templategen._is_template(path, ignore=ignore) + return Templategen._is_template(path, ignore=ignore, debug=debug) + + # is a directory for entry in os.listdir(path): fpath = os.path.join(path, entry) if not os.path.isfile(fpath): # recursively explore directory - if Templategen.is_template(fpath, ignore=ignore): + if Templategen.is_template(fpath, ignore=ignore, debug=debug): return True else: # check if file is a template - if Templategen._is_template(fpath, ignore=ignore): + if Templategen._is_template(fpath, ignore=ignore, debug=debug): return True return False @@ -244,9 +253,9 @@ class Templategen: return VAR_START in str(string) @staticmethod - def _is_template(path, ignore): + def _is_template(path, ignore, debug=False): """test if file pointed by path is a template""" - if utils.must_ignore([path], ignore, debug=False): + if utils.must_ignore([path], ignore, debug=debug): return False if not os.path.isfile(path): return False diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 6e5f91a..dc033dc 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -160,7 +160,8 @@ class Updater: return tmp def _is_template(self, path): - if not Templategen.is_template(path, ignore=self.ignores): + if not Templategen.is_template(path, ignore=self.ignores, + debug=self.debug): self.log.dbg('{} is NO template'.format(path)) return False self.log.warn('{} uses template, update manually'.format(path)) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 1fd3b26..67798ae 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -221,6 +221,8 @@ def strip_home(path): def must_ignore(paths, ignores, debug=False): """return true if any paths in list matches any ignore patterns""" + if debug: + LOG.dbg('must_ignore called', force=True) if not ignores: return False if debug: @@ -237,10 +239,14 @@ def must_ignore(paths, ignores, debug=False): LOG.dbg('ignore \"{}\" match: {}'.format(i, path), force=True) ignore_matches.append(path) + # Then remove any matches that actually shouldn't be ignored for nign in ignored_negative: # Each of these will start with an '!' so we need to remove that nign = nign[1:] + if debug: + msg = 'trying to match :\"{}\" with non-ignore-pattern:\"{}\"' + LOG.dbg(msg.format(path, nign)) if fnmatch.fnmatch(path, nign): if debug: msg = 'negative ignore \"{}\" match: {}'.format(nign, path) @@ -256,6 +262,8 @@ def must_ignore(paths, ignores, debug=False): 'previous ignore pattern.'.format(nign) ) if ignore_matches: + if debug: + LOG.dbg('ignoring {}'.format(paths), force=True) return True if debug: LOG.dbg('NOT ignoring {}'.format(paths), force=True)