source.cmd: reject empty results

also better logging
This commit is contained in:
lilydjwg 2018-04-13 23:48:12 +08:00
parent 07fe08c639
commit bb629ec561
1 changed files with 15 additions and 5 deletions

View File

@ -9,12 +9,22 @@ logger = structlog.get_logger(logger_name=__name__)
async def get_version(name, conf):
cmd = conf['cmd']
p = await asyncio.create_subprocess_shell(cmd, stdout=asyncio.subprocess.PIPE)
p = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
output = (await p.communicate())[0].strip().decode('latin1')
output, error = await p.communicate()
output = output.strip().decode('latin1')
error = output.strip().decode(errors='replace')
if p.returncode != 0:
logger.error('command exited with error',
cmd=cmd, error=error,
name=name, returncode=p.returncode)
return
return output
elif not output:
logger.error('command exited without output',
cmd=cmd, error=error,
name=name, returncode=p.returncode)
else:
return output