From 20b673be2a38e8454c89274771aa03ecdf8f01c2 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 6 Jun 2018 07:37:44 +0200 Subject: [PATCH] adding debug to templategen --- dotdrop/dotdrop.py | 4 ++-- dotdrop/templategen.py | 8 ++++++-- tests/test_compare.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 4998b35..9bbc0c4 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -83,7 +83,7 @@ def install(opts, conf): msg = 'no dotfiles defined for this profile (\"{}\")' LOG.err(msg.format(opts['profile'])) return False - t = Templategen(base=opts['dotpath']) + t = Templategen(base=opts['dotpath'], debug=opts['debug']) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'], diff=opts['installdiff'], debug=opts['debug']) @@ -140,7 +140,7 @@ def compare(opts, conf, tmp, focus=None): msg = 'no dotfiles defined for this profile (\"{}\")' LOG.err(msg.format(opts['profile'])) return True - t = Templategen(base=opts['dotpath']) + t = Templategen(base=opts['dotpath'], debug=opts['debug']) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], debug=opts['debug']) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 88316a6..f53d794 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -10,6 +10,7 @@ from jinja2 import Environment, FileSystemLoader # local imports import dotdrop.utils as utils +from dotdrop.logger import Logger BLOCK_START = '{%@@' BLOCK_END = '@@%}' @@ -21,7 +22,7 @@ COMMENT_END = '@@#}' class Templategen: - def __init__(self, base='.'): + def __init__(self, base='.', debug=False): self.base = base.rstrip(os.sep) loader = FileSystemLoader(self.base) self.env = Environment(loader=loader, @@ -33,6 +34,7 @@ class Templategen: variable_end_string=VAR_END, comment_start_string=COMMENT_START, comment_end_string=COMMENT_END) + self.log = Logger(debug=debug) def generate(self, src, profile): if not os.path.exists(src): @@ -41,8 +43,10 @@ class Templategen: def _handle_file(self, src, profile): """generate the file content from template""" - filetype = utils.run(['file', '-b', src], raw=False) + filetype = utils.run(['file', '-b', src], raw=False).strip() + self.log.dbg('\"{}\" filetype: {}'.format(src, filetype)) istext = 'text' in filetype + self.log.dbg('\"{}\" is text: {}'.format(src, istext)) if not istext: return self._handle_bin_file(src, profile) return self._handle_text_file(src, profile) diff --git a/tests/test_compare.py b/tests/test_compare.py index c61d81c..efa2f99 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -29,7 +29,7 @@ class TestCompare(unittest.TestCase): def compare(self, opts, conf, tmp, nbdotfiles): dotfiles = conf.get_dotfiles(opts['profile']) self.assertTrue(len(dotfiles) == nbdotfiles) - t = Templategen(base=opts['dotpath']) + t = Templategen(base=opts['dotpath'], debug=True) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], debug=True) results = {}