diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-04 19:58:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-04 19:58:11 +0200 |
commit | 26d6092b0e96075d532da19b973a63d2fb061869 (patch) | |
tree | c65624b134a79242fc19d02d9dc42a90cdee3674 /python/vyos/util.py | |
parent | 2364dac59628a801cec373c278860b258b014b46 (diff) | |
parent | dcbd5f430907747f8c29111fbe9f5737865a7ae8 (diff) | |
download | vyos-1x-26d6092b0e96075d532da19b973a63d2fb061869.tar.gz vyos-1x-26d6092b0e96075d532da19b973a63d2fb061869.zip |
Merge pull request #299 from thomas-mangin/T2205
ifconfig: T2205: silence ethtool harmless failures
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 5807c837d..781fd9a2c 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -16,6 +16,44 @@ import os import re import sys +from subprocess import Popen, PIPE, STDOUT + + +# debugging + + +def debug(flag): + return flag if os.path.isfile(f'/tmp/vyos.{flag}.debug') else '' + + +def debug_msg(message, section=''): + if section: + print(f'DEBUG/{section:<6} {message}') + + +# commands + + +def popen(command, section=''): + p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True) + tmp = p.communicate()[0].strip() + debug_msg(f"cmd '{command}'", section) + decoded = tmp.decode() + if decoded: + debug_msg(f"returned:\n{decoded}", section) + return decoded, p.returncode + + +def cmd(command, section=''): + decoded, code = popen(command, section) + if code != 0: + # error code can be recovered with .errno + raise OSError(code, f'{command}\nreturned: {decoded}') + return decoded + + +# file manipulation + def subprocess_cmd(command): |