Simplify code by letting run() generate exception on non zero exit status

This commit is contained in:
Ruben van Staveren 2022-03-11 20:42:19 +01:00
parent f3f8bd5dc6
commit 34f871ae75
Signed by: ruben
GPG Key ID: 886F6BECD477A93F

View File

@ -9,11 +9,9 @@ def pfctl_cfg_read(anchor):
cmd = [_SUDO, _PFCTL, '-a', anchor, '-sr'] cmd = [_SUDO, _PFCTL, '-a', anchor, '-sr']
logging.info('Running %s', cmd) logging.info('Running %s', cmd)
res = run(cmd, capture_output=True) res = run(cmd, capture_output=True, check=True)
if res and res.stdout:
logging.info('Result: %s', res) logging.info('Result: %s', res)
res.check_returncode()
return res.stdout.splitlines() return res.stdout.splitlines()
@ -24,11 +22,10 @@ def pfctl_cfg_write(anchor, cfg):
res = run(cmd, res = run(cmd,
input=cfg, input=cfg,
check=True,
capture_output=True) capture_output=True)
if res:
logging.info('Result: %s', res) logging.info('Result: %s', res)
res.check_returncode()
return res.stdout.splitlines() return res.stdout.splitlines()
@ -40,9 +37,9 @@ def pfctl_table_op(anchor, **kwargs):
logging.info('Running %s', cmd) logging.info('Running %s', cmd)
res = run([x for x in cmd if x is not None], capture_output=True) res = run([x for x in cmd if x is not None],
capture_output=True,
check=True)
if res:
logging.debug(res) logging.debug(res)
res.check_returncode()
return res.stdout.splitlines() return res.stdout.splitlines()