mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 10:14:17 +00:00
Merge pull request #296 from MarcelRobitaille/fix-istemplate-respect-ignore
Make `is_template` respect ignores
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('installing dotfile: \"{}\"'.format(dotfile.key))
|
||||||
LOG.dbg(dotfile.prt())
|
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:
|
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK:
|
||||||
# link
|
# link
|
||||||
r, err = inst.install(t, dotfile.src, dotfile.dst,
|
r, err = inst.install(t, dotfile.src, dotfile.dst,
|
||||||
@@ -222,7 +228,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
|
|||||||
dotfile.link,
|
dotfile.link,
|
||||||
actionexec=pre_actions_exec,
|
actionexec=pre_actions_exec,
|
||||||
is_template=is_template,
|
is_template=is_template,
|
||||||
chmod=dotfile.chmod)
|
chmod=dotfile.chmod,
|
||||||
|
ignore=ignores)
|
||||||
else:
|
else:
|
||||||
# nolink
|
# nolink
|
||||||
src = dotfile.src
|
src = dotfile.src
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ class Installer:
|
|||||||
else:
|
else:
|
||||||
r, err = self._link_children(templater, src, dst,
|
r, err = self._link_children(templater, src, dst,
|
||||||
actionexec=actionexec,
|
actionexec=actionexec,
|
||||||
is_template=is_template)
|
is_template=is_template,
|
||||||
|
ignore=ignore)
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('before chmod: {} err:{}'.format(r, err))
|
self.log.dbg('before chmod: {} err:{}'.format(r, err))
|
||||||
@@ -268,7 +269,7 @@ class Installer:
|
|||||||
return r, err
|
return r, err
|
||||||
|
|
||||||
def _link_children(self, templater, src, dst,
|
def _link_children(self, templater, src, dst,
|
||||||
actionexec=None, is_template=True):
|
actionexec=None, is_template=True, ignore=[]):
|
||||||
"""
|
"""
|
||||||
install link:link_children
|
install link:link_children
|
||||||
|
|
||||||
@@ -309,6 +310,13 @@ class Installer:
|
|||||||
subsrc = srcs[i]
|
subsrc = srcs[i]
|
||||||
subdst = dsts[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:
|
if self.debug:
|
||||||
self.log.dbg('symlink child {} to {}'.format(subsrc, subdst))
|
self.log.dbg('symlink child {} to {}'.format(subsrc, subdst))
|
||||||
|
|
||||||
|
|||||||
@@ -218,23 +218,26 @@ class Templategen:
|
|||||||
return data.decode('utf-8', 'replace')
|
return data.decode('utf-8', 'replace')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_template(path):
|
def is_template(path, ignore=[]):
|
||||||
"""recursively check if any file is a template within path"""
|
"""recursively check if any file is a template within path"""
|
||||||
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):
|
||||||
return False
|
return False
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
# is file
|
# is file
|
||||||
return Templategen._is_template(path)
|
return Templategen._is_template(path, ignore=ignore)
|
||||||
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):
|
if Templategen.is_template(fpath, ignore=ignore):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
# check if file is a template
|
# check if file is a template
|
||||||
if Templategen._is_template(fpath):
|
if Templategen._is_template(fpath, ignore=ignore):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -244,8 +247,10 @@ class Templategen:
|
|||||||
return VAR_START in str(string)
|
return VAR_START in str(string)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_template(path):
|
def _is_template(path, ignore):
|
||||||
"""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):
|
||||||
|
return False
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
return False
|
return False
|
||||||
if os.stat(path).st_size == 0:
|
if os.stat(path).st_size == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user