mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 19:09:44 +00:00
Make is_template respect ignores
A (false positive) "template" that should be ignored should not make `is_template` become true.
This commit is contained in:
@@ -207,7 +207,13 @@ def _dotfile_install(o, dotfile, tmpdir=None):
|
||||
LOG.dbg('installing dotfile: \"{}\"'.format(dotfile.key))
|
||||
LOG.dbg(dotfile.prt())
|
||||
|
||||
is_template = dotfile.template and Templategen.is_template(dotfile.src)
|
||||
ignores = list(set(o.install_ignore + dotfile.instignore))
|
||||
ignores = patch_ignores(ignores, dotfile.dst, debug=o.debug)
|
||||
|
||||
is_template = dotfile.template and Templategen.is_template(
|
||||
dotfile.src,
|
||||
ignore=ignores,
|
||||
)
|
||||
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK:
|
||||
# link
|
||||
r, err = inst.install(t, dotfile.src, dotfile.dst,
|
||||
@@ -222,7 +228,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
|
||||
dotfile.link,
|
||||
actionexec=pre_actions_exec,
|
||||
is_template=is_template,
|
||||
chmod=dotfile.chmod)
|
||||
chmod=dotfile.chmod,
|
||||
ignore=ignores)
|
||||
else:
|
||||
# nolink
|
||||
src = dotfile.src
|
||||
|
||||
@@ -149,7 +149,8 @@ class Installer:
|
||||
else:
|
||||
r, err = self._link_children(templater, src, dst,
|
||||
actionexec=actionexec,
|
||||
is_template=is_template)
|
||||
is_template=is_template,
|
||||
ignore=ignore)
|
||||
|
||||
if self.debug:
|
||||
self.log.dbg('before chmod: {} err:{}'.format(r, err))
|
||||
@@ -268,7 +269,7 @@ class Installer:
|
||||
return r, err
|
||||
|
||||
def _link_children(self, templater, src, dst,
|
||||
actionexec=None, is_template=True):
|
||||
actionexec=None, is_template=True, ignore=[]):
|
||||
"""
|
||||
install link:link_children
|
||||
|
||||
@@ -309,6 +310,13 @@ class Installer:
|
||||
subsrc = srcs[i]
|
||||
subdst = dsts[i]
|
||||
|
||||
if utils.must_ignore([subsrc, subdst], ignore, debug=self.debug):
|
||||
if self.debug:
|
||||
self.log.dbg(
|
||||
'ignoring install of {} to {}'.format(src, dst),
|
||||
)
|
||||
continue
|
||||
|
||||
if self.debug:
|
||||
self.log.dbg('symlink child {} to {}'.format(subsrc, subdst))
|
||||
|
||||
|
||||
@@ -218,23 +218,26 @@ class Templategen:
|
||||
return data.decode('utf-8', 'replace')
|
||||
|
||||
@staticmethod
|
||||
def is_template(path):
|
||||
def is_template(path, ignore=[]):
|
||||
"""recursively check if any file is a template within path"""
|
||||
path = os.path.expanduser(path)
|
||||
|
||||
if utils.must_ignore([path], ignore, debug=False):
|
||||
return False
|
||||
if not os.path.exists(path):
|
||||
return False
|
||||
if os.path.isfile(path):
|
||||
# is file
|
||||
return Templategen._is_template(path)
|
||||
return Templategen._is_template(path, ignore=ignore)
|
||||
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):
|
||||
if Templategen.is_template(fpath, ignore=ignore):
|
||||
return True
|
||||
else:
|
||||
# check if file is a template
|
||||
if Templategen._is_template(fpath):
|
||||
if Templategen._is_template(fpath, ignore=ignore):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -244,8 +247,10 @@ class Templategen:
|
||||
return VAR_START in str(string)
|
||||
|
||||
@staticmethod
|
||||
def _is_template(path):
|
||||
def _is_template(path, ignore):
|
||||
"""test if file pointed by path is a template"""
|
||||
if utils.must_ignore([path], ignore, debug=False):
|
||||
return False
|
||||
if not os.path.isfile(path):
|
||||
return False
|
||||
if os.stat(path).st_size == 0:
|
||||
|
||||
Reference in New Issue
Block a user