本文整理汇总了Python中glances.timer.Timer.set方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.set方法的具体用法?Python Timer.set怎么用?Python Timer.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glances.timer.Timer
的用法示例。
在下文中一共展示了Timer.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlancesAmp
# 需要导入模块: from glances.timer import Timer [as 别名]
# 或者: from glances.timer.Timer import set [as 别名]
#.........这里部分代码省略.........
if self.enable():
for k in ['regex', 'refresh']:
if k not in self.configs:
logger.warning("AMP - {}: Can not find configuration key {} in section {}".format(self.NAME, k, self.amp_name))
self.configs['enable'] = 'false'
else:
logger.debug("AMP - {} is disabled".format(self.NAME))
# Init the count to 0
self.configs['count'] = 0
return self.enable()
def get(self, key):
"""Generic method to get the item in the AMP configuration"""
if key in self.configs:
return self.configs[key]
else:
return None
def enable(self):
"""Return True|False if the AMP is enabled in the configuration file (enable=true|false)."""
ret = self.get('enable')
if ret is None:
return False
else:
return ret.lower().startswith('true')
def regex(self):
"""Return regular expression used to identified the current application."""
return self.get('regex')
def refresh(self):
"""Return refresh time in seconds for the current application monitoring process."""
return self.get('refresh')
def one_line(self):
"""Return True|False if the AMP shoukd be displayed in oneline (one_lineline=true|false)."""
ret = self.get('one_line')
if ret is None:
return False
else:
return ret.lower().startswith('true')
def time_until_refresh(self):
"""Return time in seconds until refresh."""
return self.timer.get()
def should_update(self):
"""Return True is the AMP should be updated:
- AMP is enable
- only update every 'refresh' seconds
"""
if self.timer.finished():
self.timer.set(self.refresh())
self.timer.reset()
return self.enable()
return False
def set_count(self, count):
"""Set the number of processes matching the regex"""
self.configs['count'] = count
def count(self):
"""Get the number of processes matching the regex"""
return self.get('count')
def count_min(self):
"""Get the minimum number of processes"""
return self.get('countmin')
def count_max(self):
"""Get the maximum number of processes"""
return self.get('countmax')
def set_result(self, result, separator=''):
"""Store the result (string) into the result key of the AMP
if one_line is true then replace \n by separator
"""
if self.one_line():
self.configs['result'] = str(result).replace('\n', separator)
else:
self.configs['result'] = str(result)
def result(self):
""" Return the result of the AMP (as a string)"""
ret = self.get('result')
if ret is not None:
ret = u(ret)
return ret
def update_wrapper(self, process_list):
"""Wrapper for the children update"""
# Set the number of running process
self.set_count(len(process_list))
# Call the children update method
if self.should_update():
return self.update(process_list)
else:
return self.result()