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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user