diff --git a/dotdrop/comparator.py b/dotdrop/comparator.py index b516408..27cfa5f 100644 --- a/dotdrop/comparator.py +++ b/dotdrop/comparator.py @@ -43,6 +43,8 @@ class Comparator: def _comp_dir(self, left, right, ignore): """compare a directory""" + if not os.path.exists(right): + return '' if self._ignore([left, right], ignore): if self.debug: self.log.dbg('ignoring diff {} and {}'.format(left, right)) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 6e5385d..a3bc11c 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -36,6 +36,8 @@ class Installer: def install(self, templater, src, dst): """install the src to dst using a template""" src = os.path.join(self.base, os.path.expanduser(src)) + if not os.path.exists(src): + self.log.err('source dotfile does not exist: {}'.format(src)) dst = os.path.expanduser(dst) if self.totemp: dst = self._pivot_path(dst, self.totemp) @@ -52,6 +54,8 @@ class Installer: def link(self, templater, src, dst): """set src as the link target of dst""" src = os.path.join(self.base, os.path.expanduser(src)) + if not os.path.exists(src): + self.log.err('source dotfile does not exist: {}'.format(src)) dst = os.path.expanduser(dst) if self.totemp: return self.install(templater, src, dst) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 67408eb..06138d3 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -93,6 +93,8 @@ class Templategen: def is_template(path): """recursively check if any file is a template within path""" + if not os.path.exists(path): + return False if os.path.isfile(path): # is file return Templategen._is_template(path) @@ -112,8 +114,12 @@ class Templategen: """test if file pointed by path is a template""" if not os.path.isfile(path): return False - with open(path, 'r') as f: - data = f.read() + try: + with open(path, 'r') as f: + data = f.read() + except UnicodeDecodeError: + # is binary so surely no template + return False markers = [BLOCK_START, VAR_START, COMMENT_START] for marker in markers: if marker in data: