Make dummy cpu_load_percent also ThreadedSegment
It is the easiest way to make documentation identical when created on a system with and without psutil module and deduplicate docstrings
This commit is contained in:
parent
f3ce370566
commit
14b31eca35
|
@ -573,15 +573,6 @@ try:
|
|||
|
||||
def render(self, cpu_percent, format='{0:.0f}%', **kwargs):
|
||||
return format.format(cpu_percent)
|
||||
|
||||
cpu_load_percent = with_docstring(CPULoadPercentSegment(),
|
||||
'''Return the average CPU load as a percentage.
|
||||
|
||||
Requires the ``psutil`` module.
|
||||
|
||||
:param str format:
|
||||
Output format. Accepts measured CPU load as the first argument.
|
||||
''')
|
||||
except ImportError:
|
||||
def _get_bytes(interface): # NOQA
|
||||
with open('/sys/class/net/{interface}/statistics/rx_bytes'.format(interface=interface), 'rb') as file_obj:
|
||||
|
@ -599,16 +590,35 @@ except ImportError:
|
|||
def _get_user(segment_info): # NOQA
|
||||
return segment_info['environ'].get('USER', None)
|
||||
|
||||
def cpu_load_percent(pl, measure_interval=.5): # NOQA
|
||||
'''Return the average CPU load as a percentage.
|
||||
class CPULoadPercentSegment(ThreadedSegment): # NOQA
|
||||
interval = 1
|
||||
|
||||
Requires the ``psutil`` module.
|
||||
@staticmethod
|
||||
def startup(**kwargs):
|
||||
pass
|
||||
|
||||
:param float measure_interval:
|
||||
interval used to measure CPU load (in seconds)
|
||||
'''
|
||||
pl.warn('psutil package is not installed, thus CPU load is not available')
|
||||
return None
|
||||
@staticmethod
|
||||
def start():
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def shutdown():
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def render(cpu_percent, pl, format='{0:.0f}%', **kwargs):
|
||||
pl.warn('psutil package is not installed, thus CPU load is not available')
|
||||
return None
|
||||
|
||||
|
||||
cpu_load_percent = with_docstring(CPULoadPercentSegment(),
|
||||
'''Return the average CPU load as a percentage.
|
||||
|
||||
Requires the ``psutil`` module.
|
||||
|
||||
:param str format:
|
||||
Output format. Accepts measured CPU load as the first argument.
|
||||
''')
|
||||
|
||||
|
||||
username = False
|
||||
|
|
Loading…
Reference in New Issue