2016-10-23 01:53:02 +03:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
|
|
class PluginThread(threading.Thread):
|
|
|
|
def __init__(self, section, config, thread_id):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.threadID = thread_id
|
|
|
|
self.date_format = config.get(section, 'format', fallback='%c')
|
|
|
|
self.status = dict()
|
|
|
|
if config.has_option(section, 'color'):
|
|
|
|
self.status['color'] = config.get(section, 'color')
|
2016-10-23 02:27:27 +03:00
|
|
|
self.freq = config.getint(section, 'freq', fallback=10)
|
2016-11-03 17:59:00 +02:00
|
|
|
self.hide_ok = config.getboolean(section, 'hide_ok', fallback=False)
|
2016-10-25 19:48:40 +03:00
|
|
|
self.hide = False
|
2016-11-18 17:42:28 +02:00
|
|
|
self.should_stop = False
|
2016-10-31 14:20:07 +02:00
|
|
|
self.problem_value = config.getint(section, 'problem', fallback=100)
|
2016-10-23 01:53:02 +03:00
|
|
|
|
|
|
|
def main(self):
|
|
|
|
loads = os.getloadavg()
|
2016-10-31 14:20:07 +02:00
|
|
|
if loads[0] >= self.problem_value:
|
|
|
|
self.hide = False
|
|
|
|
self.status['urgent'] = True
|
|
|
|
else:
|
2016-11-03 17:59:00 +02:00
|
|
|
self.hide = self.hide_ok
|
2016-10-31 14:20:07 +02:00
|
|
|
self.status['urgent'] = False
|
2016-10-23 01:53:02 +03:00
|
|
|
loads = [str(i) for i in loads]
|
|
|
|
self.status['full_text'] = 'LA: ' + ' '.join(loads)
|
|
|
|
|
2016-11-18 17:42:28 +02:00
|
|
|
def stop(self):
|
|
|
|
self.should_stop = True
|
|
|
|
|
2016-10-23 01:53:02 +03:00
|
|
|
def run(self):
|
|
|
|
while True:
|
2016-11-18 17:42:28 +02:00
|
|
|
if self.should_stop is False:
|
|
|
|
self.main()
|
|
|
|
time.sleep(self.freq)
|
|
|
|
else:
|
|
|
|
break
|