1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 06:48:49 +00:00

adding return code of external command for #60

This commit is contained in:
deadc0de6
2018-09-28 13:51:57 +02:00
parent f252e7fb3b
commit 1ea1e004e5
2 changed files with 10 additions and 5 deletions

View File

@@ -279,14 +279,14 @@ def importer(opts, conf, paths):
if opts['dry']:
LOG.dry('would run: {}'.format(' '.join(cmd)))
else:
run(cmd, raw=False, debug=opts['debug'])
run(cmd, raw=False, debug=opts['debug'], checkerr=True)
cmd = ['cp', '-R', '-L', dst, srcf]
if opts['dry']:
LOG.dry('would run: {}'.format(' '.join(cmd)))
if linkit:
LOG.dry('would symlink {} to {}'.format(srcf, dst))
else:
run(cmd, raw=False, debug=opts['debug'])
run(cmd, raw=False, debug=opts['debug'], checkerr=True)
if linkit:
remove(dst)
os.symlink(srcf, dst)

View File

@@ -18,15 +18,20 @@ from dotdrop.version import __version__ as VERSION
LOG = Logger()
def run(cmd, raw=True, debug=False):
def run(cmd, raw=True, debug=False, checkerr=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)
p.wait()
out = p.stdout.readlines()
ret = p.returncode
if checkerr and ret != 0:
LOG.warn('cmd \"{}\" returned non zero ({}): {}'.format(ret, out))
if raw:
return p.stdout.readlines()
lines = [x.decode('utf-8', 'replace') for x in p.stdout.readlines()]
return out
lines = [x.decode('utf-8', 'replace') for x in out]
return ''.join(lines)