mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 23:04:15 +00:00
create directory hierarchy even when not containing files
This commit is contained in:
@@ -249,7 +249,7 @@ def update(opts, conf, path):
|
|||||||
if opts['safe'] and not LOG.ask(msg):
|
if opts['safe'] and not LOG.ask(msg):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False)
|
run(cmd, raw=False, debug=opts['debug'])
|
||||||
LOG.log('\"{}\" updated from \"{}\".'.format(src, path))
|
LOG.log('\"{}\" updated from \"{}\".'.format(src, path))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -283,14 +283,14 @@ def importer(opts, conf, paths):
|
|||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False)
|
run(cmd, raw=False, debug=opts['debug'])
|
||||||
cmd = ['cp', '-R', '-L', dst, srcf]
|
cmd = ['cp', '-R', '-L', dst, srcf]
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||||
if opts['link']:
|
if opts['link']:
|
||||||
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False)
|
run(cmd, raw=False, debug=opts['debug'])
|
||||||
if opts['link']:
|
if opts['link']:
|
||||||
remove(dst)
|
remove(dst)
|
||||||
os.symlink(srcf, dst)
|
os.symlink(srcf, dst)
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ class Installer:
|
|||||||
def _handle_dir(self, templater, profile, src, dst):
|
def _handle_dir(self, templater, profile, src, dst):
|
||||||
"""install src to dst when is a directory"""
|
"""install src to dst when is a directory"""
|
||||||
ret = []
|
ret = []
|
||||||
|
self._create_dirs(dst)
|
||||||
|
# handle all files in dir
|
||||||
for entry in os.listdir(src):
|
for entry in os.listdir(src):
|
||||||
f = os.path.join(src, entry)
|
f = os.path.join(src, entry)
|
||||||
if not os.path.isdir(f):
|
if not os.path.isdir(f):
|
||||||
@@ -161,6 +163,9 @@ class Installer:
|
|||||||
return False
|
return False
|
||||||
if os.path.exists(directory):
|
if os.path.exists(directory):
|
||||||
return True
|
return True
|
||||||
|
if self.dry:
|
||||||
|
self.log.dry('would mkdir -p {}'.format(directory))
|
||||||
|
return True
|
||||||
self.log.dbg('mkdir -p {}'.format(directory))
|
self.log.dbg('mkdir -p {}'.format(directory))
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
return os.path.exists(directory)
|
return os.path.exists(directory)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Templategen:
|
|||||||
|
|
||||||
def __init__(self, base='.', debug=False):
|
def __init__(self, base='.', debug=False):
|
||||||
self.base = base.rstrip(os.sep)
|
self.base = base.rstrip(os.sep)
|
||||||
|
self.debug = debug
|
||||||
loader = FileSystemLoader(self.base)
|
loader = FileSystemLoader(self.base)
|
||||||
self.env = Environment(loader=loader,
|
self.env = Environment(loader=loader,
|
||||||
trim_blocks=True, lstrip_blocks=True,
|
trim_blocks=True, lstrip_blocks=True,
|
||||||
@@ -43,7 +44,8 @@ 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).strip()
|
filetype = utils.run(['file', '-b', src], raw=False, debug=self.debug)
|
||||||
|
filetype = filetype.strip()
|
||||||
self.log.dbg('\"{}\" filetype: {}'.format(src, filetype))
|
self.log.dbg('\"{}\" filetype: {}'.format(src, filetype))
|
||||||
istext = 'text' in filetype
|
istext = 'text' in filetype
|
||||||
self.log.dbg('\"{}\" is text: {}'.format(src, istext))
|
self.log.dbg('\"{}\" is text: {}'.format(src, istext))
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ from shutil import rmtree
|
|||||||
# local import
|
# local import
|
||||||
from dotdrop.logger import Logger
|
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)"""
|
"""run a command in the shell (expects a list)"""
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('exec: {}'.format(' '.join(cmd)))
|
||||||
p = subprocess.Popen(cmd, shell=False,
|
p = subprocess.Popen(cmd, shell=False,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
if raw:
|
if raw:
|
||||||
|
|||||||
Reference in New Issue
Block a user