Fix regex for block devices retrieving and clean up in yunohost_monitor.py

This commit is contained in:
Jerome Lebleu 2013-12-05 14:32:36 +01:00
parent b685ab5a77
commit 5f8f1637ab

View file

@ -55,13 +55,15 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False):
devices = {} devices = {}
output = subprocess.check_output('lsblk -o NAME,MOUNTPOINT -l -n'.split()) output = subprocess.check_output('lsblk -o NAME,MOUNTPOINT -l -n'.split())
for d in output.split('\n'): for d in output.split('\n'):
m = re.search(r'([a-z]+[0-9]+)[ ]+(\/\S*)', d) # Extract device name (1) and its mountpoint (2) m = re.search(r'([a-z]+[0-9]*)[ ]+(\/\S*)', d) # Extract device name (1) and its mountpoint (2)
if m and (mountpoint is None or m.group(2) == mountpoint): if m and (mountpoint is None or m.group(2) == mountpoint):
(dn, dm) = (m.group(1), m.group(2)) (dn, dm) = (m.group(1), m.group(2))
devices[dn] = dm devices[dn] = dm
result[dn] = {} if len(units) > 1 else [] result[dn] = {} if len(units) > 1 else []
result_dname = dn if mountpoint is not None else None result_dname = dn if mountpoint is not None else None
if len(devices) == 0: if len(devices) == 0:
if mountpoint is None:
raise YunoHostError(1, _("No mounted block device found"))
raise YunoHostError(1, _("Unknown mountpoint '%s'") % mountpoint) raise YunoHostError(1, _("Unknown mountpoint '%s'") % mountpoint)
# Retrieve monitoring for unit(s) # Retrieve monitoring for unit(s)
@ -216,33 +218,6 @@ def monitor_system(units=None, human_readable=False):
return result return result
def monitor_process(enable=None, disable=None, start=None, stop=None, check=False, info=False):
"""
Check Process
Keyword argument:
info -- Process info
disable -- Disable process
enable -- Enable process
start -- Start process
check -- Check process
stop -- Stop process
"""
if enable:
return process_enable(enable)
elif disable:
return process_disable(disable)
elif start:
return process_start(start)
elif stop:
return process_stop(stop)
elif check:
return process_check(check)
elif info:
return json.loads(s.getProcessCount())
def _get_glances_api(): def _get_glances_api():
""" """
Retrieve Glances API running on the local server Retrieve Glances API running on the local server