Skip to content
Snippets Groups Projects
Commit b1bd3f1d authored by Henning Glawe's avatar Henning Glawe
Browse files

catch errors of system commands

parent 4f74bd2d
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ def get_ceph_attribute(path: str, attribute: str) -> int: ...@@ -45,7 +45,7 @@ def get_ceph_attribute(path: str, attribute: str) -> int:
return int(output) return int(output)
def df_ceph(path_obj: pathlib.Path) -> Tuple[int, int, int]: def df_ceph(path: pathlib.Path) -> Tuple[int, int, int]:
""" """
Given a path (such as '/scratch/fangohr') return the number of bytes Given a path (such as '/scratch/fangohr') return the number of bytes
(size, used, available). (size, used, available).
...@@ -57,14 +57,17 @@ def df_ceph(path_obj: pathlib.Path) -> Tuple[int, int, int]: ...@@ -57,14 +57,17 @@ def df_ceph(path_obj: pathlib.Path) -> Tuple[int, int, int]:
>>> df_ceph("/scratch/fangohr") >>> df_ceph("/scratch/fangohr")
(25000000000000, 1780686359, 24998219313641) (25000000000000, 1780686359, 24998219313641)
""" """
path = str(path_obj) try:
used = get_ceph_attribute(path, "ceph.dir.rbytes") used = get_ceph_attribute(path, "ceph.dir.rbytes")
size = get_ceph_attribute(path, "ceph.quota.max_bytes") size = get_ceph_attribute(path, "ceph.quota.max_bytes")
avail = size - used except:
used, size, avail = None, None, None
else:
avail = size - used
return size, used, avail return size, used, avail
def df_mountpoint(path_obj: pathlib.Path) -> Tuple[int, int, int]: def df_mountpoint(path: pathlib.Path) -> Tuple[int, int, int]:
""" """
Given a path (such as '/home/fangohr') return the number of bytes Given a path (such as '/home/fangohr') return the number of bytes
(size, used, available). (size, used, available).
...@@ -76,9 +79,12 @@ def df_mountpoint(path_obj: pathlib.Path) -> Tuple[int, int, int]: ...@@ -76,9 +79,12 @@ def df_mountpoint(path_obj: pathlib.Path) -> Tuple[int, int, int]:
>>> df("/home/fangohr") >>> df("/home/fangohr")
(25000000000000, 1780686359, 24998219313641) (25000000000000, 1780686359, 24998219313641)
""" """
path = str(path_obj) size, used, avail = None, None, None
cmd = ["df", "--block-size=1", path] cmd = ["df", "--block-size=1", path]
df_run = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, text=True) try:
df_run = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, text=True)
except:
return None, None, None
for line in df_run.stdout.splitlines(): for line in df_run.stdout.splitlines():
l = line.split() l = line.split()
if (l[0] == "Filesystem"): if (l[0] == "Filesystem"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment