diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index d835760..dca6c4b 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -249,7 +249,7 @@ def update(opts, conf, path): if opts['safe'] and not LOG.ask(msg): return False else: - run(cmd, raw=False) + run(cmd, raw=False, debug=opts['debug']) LOG.log('\"{}\" updated from \"{}\".'.format(src, path)) return True @@ -283,14 +283,14 @@ def importer(opts, conf, paths): if opts['dry']: LOG.dry('would run: {}'.format(' '.join(cmd))) else: - run(cmd, raw=False) + run(cmd, raw=False, debug=opts['debug']) cmd = ['cp', '-R', '-L', dst, srcf] if opts['dry']: LOG.dry('would run: {}'.format(' '.join(cmd))) if opts['link']: LOG.dry('would symlink {} to {}'.format(srcf, dst)) else: - run(cmd, raw=False) + run(cmd, raw=False, debug=opts['debug']) if opts['link']: remove(dst) os.symlink(srcf, dst) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 540c3cc..135445f 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -104,6 +104,8 @@ class Installer: def _handle_dir(self, templater, profile, src, dst): """install src to dst when is a directory""" ret = [] + self._create_dirs(dst) + # handle all files in dir for entry in os.listdir(src): f = os.path.join(src, entry) if not os.path.isdir(f): @@ -161,6 +163,9 @@ class Installer: return False if os.path.exists(directory): return True + if self.dry: + self.log.dry('would mkdir -p {}'.format(directory)) + return True self.log.dbg('mkdir -p {}'.format(directory)) os.makedirs(directory) return os.path.exists(directory) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index f53d794..1809c93 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -24,6 +24,7 @@ class Templategen: def __init__(self, base='.', debug=False): self.base = base.rstrip(os.sep) + self.debug = debug loader = FileSystemLoader(self.base) self.env = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True, @@ -43,7 +44,8 @@ class Templategen: def _handle_file(self, src, profile): """generate the file content from template""" - filetype = utils.run(['file', '-b', src], raw=False).strip() + filetype = utils.run(['file', '-b', src], raw=False, debug=self.debug) + filetype = filetype.strip() self.log.dbg('\"{}\" filetype: {}'.format(src, filetype)) istext = 'text' in filetype self.log.dbg('\"{}\" is text: {}'.format(src, istext)) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 5a39c22..0038626 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -14,9 +14,13 @@ from shutil import rmtree # local import from dotdrop.logger import Logger +LOG = Logger() -def run(cmd, raw=True): + +def run(cmd, raw=True, debug=False): """run a command in the shell (expects a list)""" + if debug: + LOG.dbg('exec: {}'.format(' '.join(cmd))) p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if raw: