From 00655952378ccdb1793f0b4d679ad0c92ecf315d Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 1 Sep 2018 19:00:54 +0200 Subject: [PATCH] better identify templates --- dotdrop/templategen.py | 13 ++++++++++--- dotdrop/updater.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 8d5fb14..a131961 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -91,6 +91,13 @@ class Templategen: data = f.read() return data.decode('utf-8', 'replace') - def get_marker(): - """return identifier for template dotfile""" - return BLOCK_START + def is_template(path): + if not os.path.exists(path): + return False + with open(path, 'r') as f: + data = f.read() + markers = [BLOCK_START, VAR_START, COMMENT_START] + for marker in markers: + if marker in data: + return True + return False diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 57c02c4..3dcd57d 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -76,7 +76,7 @@ class Updater: return self._handle_file(left, right) def _is_template(self, path): - if Templategen.get_marker() not in open(path, 'r').read(): + if not Templategen.is_template(path): return False self.log.warn('{} uses template, update manually'.format(path)) return True