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:
ZyX 2013-04-07 19:01:54 +04:00
parent f3ce370566
commit 14b31eca35

View File

@ -573,15 +573,6 @@ try:
def render(self, cpu_percent, format='{0:.0f}%', **kwargs): def render(self, cpu_percent, format='{0:.0f}%', **kwargs):
return format.format(cpu_percent) 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: except ImportError:
def _get_bytes(interface): # NOQA def _get_bytes(interface): # NOQA
with open('/sys/class/net/{interface}/statistics/rx_bytes'.format(interface=interface), 'rb') as file_obj: 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 def _get_user(segment_info): # NOQA
return segment_info['environ'].get('USER', None) return segment_info['environ'].get('USER', None)
def cpu_load_percent(pl, measure_interval=.5): # NOQA class CPULoadPercentSegment(ThreadedSegment): # NOQA
interval = 1
@staticmethod
def startup(**kwargs):
pass
@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. '''Return the average CPU load as a percentage.
Requires the ``psutil`` module. Requires the ``psutil`` module.
:param float measure_interval: :param str format:
interval used to measure CPU load (in seconds) Output format. Accepts measured CPU load as the first argument.
''' ''')
pl.warn('psutil package is not installed, thus CPU load is not available')
return None
username = False username = False