1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 08:58:29 +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:
Marcel Robitaille
2020-12-11 01:34:09 -05:00
parent 12c3c97aef
commit 071d74fb38
3 changed files with 29 additions and 9 deletions

View File

@@ -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: