nvchecker/nvchecker_source/cmd.py

34 lines
900 B
Python
Raw Normal View History

2017-02-28 07:24:53 +00:00
# MIT licensed
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
2017-02-28 07:24:53 +00:00
2017-07-04 09:04:29 +00:00
import asyncio
2013-11-03 10:21:50 +00:00
2018-04-11 08:18:41 +00:00
import structlog
logger = structlog.get_logger(logger_name=__name__)
2013-11-03 10:21:50 +00:00
def cacher(name, conf):
return conf['cmd']
async def get_version(name, conf, *, keymanager=None):
2013-11-03 10:21:50 +00:00
cmd = conf['cmd']
p = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
2013-11-03 10:21:50 +00:00
output, error = await p.communicate()
output = output.strip().decode('latin1')
2018-04-13 15:59:18 +00:00
error = error.strip().decode(errors='replace')
2017-07-04 09:04:29 +00:00
if p.returncode != 0:
2018-04-11 08:18:41 +00:00
logger.error('command exited with error',
cmd=cmd, error=error,
2018-04-11 08:18:41 +00:00
name=name, returncode=p.returncode)
elif not output:
logger.error('command exited without output',
cmd=cmd, error=error,
name=name, returncode=p.returncode)
else:
return output