mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 21:49:00 +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']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False, debug=opts['debug'])
|
run(cmd, raw=False, debug=opts['debug'], checkerr=True)
|
||||||
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 linkit:
|
if linkit:
|
||||||
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False, debug=opts['debug'])
|
run(cmd, raw=False, debug=opts['debug'], checkerr=True)
|
||||||
if linkit:
|
if linkit:
|
||||||
remove(dst)
|
remove(dst)
|
||||||
os.symlink(srcf, dst)
|
os.symlink(srcf, dst)
|
||||||
|
|||||||
@@ -18,15 +18,20 @@ from dotdrop.version import __version__ as VERSION
|
|||||||
LOG = Logger()
|
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)"""
|
"""run a command in the shell (expects a list)"""
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('exec: {}'.format(' '.join(cmd)))
|
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)
|
||||||
|
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:
|
if raw:
|
||||||
return p.stdout.readlines()
|
return out
|
||||||
lines = [x.decode('utf-8', 'replace') for x in p.stdout.readlines()]
|
lines = [x.decode('utf-8', 'replace') for x in out]
|
||||||
return ''.join(lines)
|
return ''.join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user