2016-10-23 01:53:02 +03:00
|
|
|
import psutil
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
class PluginThread(threading.Thread):
|
|
|
|
def __init__(self, section, config, thread_id):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.threadID = thread_id
|
|
|
|
self.status = dict()
|
|
|
|
self.part = config.get(section, 'part')
|
|
|
|
if config.has_option(section, 'color'):
|
|
|
|
self.status['color'] = config.get(section, 'color')
|
|
|
|
self.freq = config.getint(section, 'freq', fallback=30)
|
2016-10-25 19:48:40 +03:00
|
|
|
self.hide = False
|
2016-10-31 14:10:30 +02:00
|
|
|
self.problem_value = config.getint(section, 'problem', fallback=70)
|
2016-10-23 01:53:02 +03:00
|
|
|
|
|
|
|
def main(self):
|
|
|
|
du_stat = psutil.disk_usage(self.part)
|
2016-10-31 14:10:30 +02:00
|
|
|
if du_stat.percent >= self.problem_value:
|
|
|
|
self.hide = False
|
|
|
|
self.status['urgent'] = True
|
|
|
|
else:
|
|
|
|
self.hide = True
|
|
|
|
self.status['urgent'] = False
|
2016-10-23 01:53:02 +03:00
|
|
|
du_free = str(round(du_stat.free / 2**30, 2))
|
|
|
|
du = self.part + ': ' + du_free + 'G'
|
|
|
|
self.status['full_text'] = du
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
self.main()
|
|
|
|
time.sleep(self.freq)
|