mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-22 15:30:09 +00:00
Error handling in subprocess run (#516)
This commit is contained in:
parent
0abbff200e
commit
aa0e5a287b
@ -44,6 +44,7 @@ def running_env():
|
|||||||
git contains the git hash of the checked out code
|
git contains the git hash of the checked out code
|
||||||
env is the various system information where this app is running
|
env is the various system information where this app is running
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
ra_git_version = (
|
ra_git_version = (
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["git", "rev-parse", "HEAD"],
|
["git", "rev-parse", "HEAD"],
|
||||||
@ -53,6 +54,12 @@ def running_env():
|
|||||||
.stdout.decode("utf-8")
|
.stdout.decode("utf-8")
|
||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
logging.warning("Executed shell command: %s", " ".join(error.cmd))
|
||||||
|
logging.warning("Got error: %s", error.stderr.decode("utf-8"))
|
||||||
|
ra_git_version = ""
|
||||||
|
|
||||||
|
try:
|
||||||
pi_version = (
|
pi_version = (
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["uname", "-a"],
|
["uname", "-a"],
|
||||||
@ -62,6 +69,11 @@ def running_env():
|
|||||||
.stdout.decode("utf-8")
|
.stdout.decode("utf-8")
|
||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
logging.warning("Executed shell command: %s", " ".join(error.cmd))
|
||||||
|
logging.warning("Got error: %s", error.stderr.decode("utf-8"))
|
||||||
|
pi_version = "Unknown"
|
||||||
|
|
||||||
return {"git": ra_git_version, "env": pi_version}
|
return {"git": ra_git_version, "env": pi_version}
|
||||||
|
|
||||||
|
|
||||||
@ -70,28 +82,46 @@ def running_proc(daemon):
|
|||||||
Takes (str) daemon
|
Takes (str) daemon
|
||||||
Returns (int) proc, which is the number of processes currently running
|
Returns (int) proc, which is the number of processes currently running
|
||||||
"""
|
"""
|
||||||
process = subprocess.run(
|
try:
|
||||||
|
processes = (
|
||||||
|
subprocess.run(
|
||||||
["ps", "aux"],
|
["ps", "aux"],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
output = process.stdout.decode("utf-8")
|
.stdout.decode("utf-8")
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
logging.warning("Executed shell command: %s", " ".join(error.cmd))
|
||||||
|
logging.warning("Got error: %s", error.stderr.decode("utf-8"))
|
||||||
|
processes = ""
|
||||||
|
|
||||||
from re import findall
|
from re import findall
|
||||||
proc = findall(daemon, output)
|
matching_processes = findall(daemon, processes)
|
||||||
return len(proc)
|
return len(matching_processes)
|
||||||
|
|
||||||
|
|
||||||
def is_bridge_setup():
|
def is_bridge_setup():
|
||||||
"""
|
"""
|
||||||
Returns (bool) True if the rascsi_bridge network interface exists
|
Returns (bool) True if the rascsi_bridge network interface exists
|
||||||
"""
|
"""
|
||||||
process = subprocess.run(
|
try:
|
||||||
|
bridges = (
|
||||||
|
subprocess.run(
|
||||||
["brctl", "show"],
|
["brctl", "show"],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
output = process.stdout.decode("utf-8")
|
.stdout.decode("utf-8")
|
||||||
if "rascsi_bridge" in output:
|
.strip()
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
logging.warning("Executed shell command: %s", " ".join(error.cmd))
|
||||||
|
logging.warning("Got error: %s", error.stderr.decode("utf-8"))
|
||||||
|
bridges = ""
|
||||||
|
|
||||||
|
if "rascsi_bridge" in bridges:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user