mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 10:36:11 +00:00
adding debug to templategen
This commit is contained in:
@@ -83,7 +83,7 @@ def install(opts, conf):
|
|||||||
msg = 'no dotfiles defined for this profile (\"{}\")'
|
msg = 'no dotfiles defined for this profile (\"{}\")'
|
||||||
LOG.err(msg.format(opts['profile']))
|
LOG.err(msg.format(opts['profile']))
|
||||||
return False
|
return False
|
||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'], debug=opts['debug'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
||||||
diff=opts['installdiff'], debug=opts['debug'])
|
diff=opts['installdiff'], debug=opts['debug'])
|
||||||
@@ -140,7 +140,7 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
msg = 'no dotfiles defined for this profile (\"{}\")'
|
msg = 'no dotfiles defined for this profile (\"{}\")'
|
||||||
LOG.err(msg.format(opts['profile']))
|
LOG.err(msg.format(opts['profile']))
|
||||||
return True
|
return True
|
||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'], debug=opts['debug'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], base=opts['dotpath'],
|
dry=opts['dry'], base=opts['dotpath'],
|
||||||
debug=opts['debug'])
|
debug=opts['debug'])
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from jinja2 import Environment, FileSystemLoader
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import dotdrop.utils as utils
|
import dotdrop.utils as utils
|
||||||
|
from dotdrop.logger import Logger
|
||||||
|
|
||||||
BLOCK_START = '{%@@'
|
BLOCK_START = '{%@@'
|
||||||
BLOCK_END = '@@%}'
|
BLOCK_END = '@@%}'
|
||||||
@@ -21,7 +22,7 @@ COMMENT_END = '@@#}'
|
|||||||
|
|
||||||
class Templategen:
|
class Templategen:
|
||||||
|
|
||||||
def __init__(self, base='.'):
|
def __init__(self, base='.', debug=False):
|
||||||
self.base = base.rstrip(os.sep)
|
self.base = base.rstrip(os.sep)
|
||||||
loader = FileSystemLoader(self.base)
|
loader = FileSystemLoader(self.base)
|
||||||
self.env = Environment(loader=loader,
|
self.env = Environment(loader=loader,
|
||||||
@@ -33,6 +34,7 @@ class Templategen:
|
|||||||
variable_end_string=VAR_END,
|
variable_end_string=VAR_END,
|
||||||
comment_start_string=COMMENT_START,
|
comment_start_string=COMMENT_START,
|
||||||
comment_end_string=COMMENT_END)
|
comment_end_string=COMMENT_END)
|
||||||
|
self.log = Logger(debug=debug)
|
||||||
|
|
||||||
def generate(self, src, profile):
|
def generate(self, src, profile):
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
@@ -41,8 +43,10 @@ class Templategen:
|
|||||||
|
|
||||||
def _handle_file(self, src, profile):
|
def _handle_file(self, src, profile):
|
||||||
"""generate the file content from template"""
|
"""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
|
istext = 'text' in filetype
|
||||||
|
self.log.dbg('\"{}\" is text: {}'.format(src, istext))
|
||||||
if not istext:
|
if not istext:
|
||||||
return self._handle_bin_file(src, profile)
|
return self._handle_bin_file(src, profile)
|
||||||
return self._handle_text_file(src, profile)
|
return self._handle_text_file(src, profile)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class TestCompare(unittest.TestCase):
|
|||||||
def compare(self, opts, conf, tmp, nbdotfiles):
|
def compare(self, opts, conf, tmp, nbdotfiles):
|
||||||
dotfiles = conf.get_dotfiles(opts['profile'])
|
dotfiles = conf.get_dotfiles(opts['profile'])
|
||||||
self.assertTrue(len(dotfiles) == nbdotfiles)
|
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'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], base=opts['dotpath'], debug=True)
|
dry=opts['dry'], base=opts['dotpath'], debug=True)
|
||||||
results = {}
|
results = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user