mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 23:59:16 +00:00
refactor ignore and debug logs
This commit is contained in:
@@ -139,7 +139,9 @@ def _dotfile_compare(opts, dotfile, tmp):
|
|||||||
ignores = patch_ignores(ignores, dotfile.dst, debug=opts.debug)
|
ignores = patch_ignores(ignores, dotfile.dst, debug=opts.debug)
|
||||||
|
|
||||||
insttmp = None
|
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
|
# install dotfile to temporary dir for compare
|
||||||
ret, err, insttmp = inst.install_to_temp(templ, tmp, src, dotfile.dst,
|
ret, err, insttmp = inst.install_to_temp(templ, tmp, src, dotfile.dst,
|
||||||
is_template=True,
|
is_template=True,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ VAR_START = '{{@@'
|
|||||||
VAR_END = '@@}}'
|
VAR_END = '@@}}'
|
||||||
COMMENT_START = '{#@@'
|
COMMENT_START = '{#@@'
|
||||||
COMMENT_END = '@@#}'
|
COMMENT_END = '@@#}'
|
||||||
|
LOG = Logger()
|
||||||
|
|
||||||
|
|
||||||
class Templategen:
|
class Templategen:
|
||||||
@@ -215,26 +216,34 @@ class Templategen:
|
|||||||
return data.decode('utf-8', 'replace')
|
return data.decode('utf-8', 'replace')
|
||||||
|
|
||||||
@staticmethod
|
@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"""
|
"""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)
|
path = os.path.expanduser(path)
|
||||||
|
|
||||||
if utils.must_ignore([path], ignore, debug=False):
|
|
||||||
return False
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
# does not exist
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if utils.must_ignore([path], ignore, debug=debug):
|
||||||
|
# must be ignored
|
||||||
|
return False
|
||||||
|
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
# is file
|
# 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):
|
for entry in os.listdir(path):
|
||||||
fpath = os.path.join(path, entry)
|
fpath = os.path.join(path, entry)
|
||||||
if not os.path.isfile(fpath):
|
if not os.path.isfile(fpath):
|
||||||
# recursively explore directory
|
# recursively explore directory
|
||||||
if Templategen.is_template(fpath, ignore=ignore):
|
if Templategen.is_template(fpath, ignore=ignore, debug=debug):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
# check if file is a template
|
# 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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -244,9 +253,9 @@ class Templategen:
|
|||||||
return VAR_START in str(string)
|
return VAR_START in str(string)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_template(path, ignore):
|
def _is_template(path, ignore, debug=False):
|
||||||
"""test if file pointed by path is a template"""
|
"""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
|
return False
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ class Updater:
|
|||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
def _is_template(self, path):
|
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))
|
self.log.dbg('{} is NO template'.format(path))
|
||||||
return False
|
return False
|
||||||
self.log.warn('{} uses template, update manually'.format(path))
|
self.log.warn('{} uses template, update manually'.format(path))
|
||||||
|
|||||||
@@ -221,6 +221,8 @@ def strip_home(path):
|
|||||||
|
|
||||||
def must_ignore(paths, ignores, debug=False):
|
def must_ignore(paths, ignores, debug=False):
|
||||||
"""return true if any paths in list matches any ignore patterns"""
|
"""return true if any paths in list matches any ignore patterns"""
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('must_ignore called', force=True)
|
||||||
if not ignores:
|
if not ignores:
|
||||||
return False
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
@@ -237,10 +239,14 @@ def must_ignore(paths, ignores, debug=False):
|
|||||||
LOG.dbg('ignore \"{}\" match: {}'.format(i, path),
|
LOG.dbg('ignore \"{}\" match: {}'.format(i, path),
|
||||||
force=True)
|
force=True)
|
||||||
ignore_matches.append(path)
|
ignore_matches.append(path)
|
||||||
|
|
||||||
# Then remove any matches that actually shouldn't be ignored
|
# Then remove any matches that actually shouldn't be ignored
|
||||||
for nign in ignored_negative:
|
for nign in ignored_negative:
|
||||||
# Each of these will start with an '!' so we need to remove that
|
# Each of these will start with an '!' so we need to remove that
|
||||||
nign = nign[1:]
|
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 fnmatch.fnmatch(path, nign):
|
||||||
if debug:
|
if debug:
|
||||||
msg = 'negative ignore \"{}\" match: {}'.format(nign, path)
|
msg = 'negative ignore \"{}\" match: {}'.format(nign, path)
|
||||||
@@ -256,6 +262,8 @@ def must_ignore(paths, ignores, debug=False):
|
|||||||
'previous ignore pattern.'.format(nign)
|
'previous ignore pattern.'.format(nign)
|
||||||
)
|
)
|
||||||
if ignore_matches:
|
if ignore_matches:
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('ignoring {}'.format(paths), force=True)
|
||||||
return True
|
return True
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('NOT ignoring {}'.format(paths), force=True)
|
LOG.dbg('NOT ignoring {}'.format(paths), force=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user