some primitive exit handling, still have to do something about waiting till the longest freq value is reached
This commit is contained in:
parent
9db9a935d4
commit
49d14d410a
7 changed files with 74 additions and 19 deletions
|
@ -14,6 +14,7 @@ class PluginThread(threading.Thread):
|
|||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = config.getint(section, 'freq', fallback=1)
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
|
||||
def main(self):
|
||||
with open(BATTERY_DIR + 'capacity', 'r') as capacity, \
|
||||
|
@ -34,7 +35,13 @@ class PluginThread(threading.Thread):
|
|||
|
||||
self.status['full_text'] = batt
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -12,11 +12,18 @@ class PluginThread(threading.Thread):
|
|||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = config.getint(section, 'freq', fallback=1)
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
|
||||
def main(self):
|
||||
self.status['full_text'] = time.strftime(self.date_format)
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -13,6 +13,7 @@ class PluginThread(threading.Thread):
|
|||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = config.getint(section, 'freq', fallback=30)
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
self.problem_value = config.getint(section, 'problem', fallback=70)
|
||||
|
||||
def main(self):
|
||||
|
@ -27,7 +28,13 @@ class PluginThread(threading.Thread):
|
|||
du = self.part + ': ' + du_free + 'G'
|
||||
self.status['full_text'] = du
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -14,6 +14,7 @@ class PluginThread(threading.Thread):
|
|||
self.freq = config.getint(section, 'freq', fallback=10)
|
||||
self.hide_ok = config.getboolean(section, 'hide_ok', fallback=False)
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
self.problem_value = config.getint(section, 'problem', fallback=100)
|
||||
|
||||
def main(self):
|
||||
|
@ -27,7 +28,13 @@ class PluginThread(threading.Thread):
|
|||
loads = [str(i) for i in loads]
|
||||
self.status['full_text'] = 'LA: ' + ' '.join(loads)
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -12,6 +12,7 @@ class PluginThread(threading.Thread):
|
|||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = config.getint(section, 'freq', fallback=1)
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
|
||||
def main(self):
|
||||
mem_stat = psutil.virtual_memory()
|
||||
|
@ -19,7 +20,13 @@ class PluginThread(threading.Thread):
|
|||
mem = 'RAM: ' + mem_available + 'G'
|
||||
self.status['full_text'] = mem
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -15,6 +15,7 @@ class PluginThread(threading.Thread):
|
|||
self.freq = config.getint(section, 'freq', fallback=5)
|
||||
self.format_status('n/a')
|
||||
self.hide = False
|
||||
self.should_stop = False
|
||||
|
||||
def format_status(self, state):
|
||||
self.status['full_text'] = self.title + ': ' + state
|
||||
|
@ -34,7 +35,20 @@ class PluginThread(threading.Thread):
|
|||
break
|
||||
self.format_status('off')
|
||||
|
||||
def sleep(self):
|
||||
seconds = 0
|
||||
while seconds < self.freq:
|
||||
time.sleep(1)
|
||||
seconds += 1
|
||||
del seconds
|
||||
|
||||
def stop(self):
|
||||
self.should_stop = True
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
if self.should_stop is False:
|
||||
self.main()
|
||||
self.sleep()
|
||||
else:
|
||||
break
|
||||
|
|
20
vdstatus
20
vdstatus
|
@ -1,22 +1,23 @@
|
|||
#!/usr/bin/python3
|
||||
# TODO: handle SIGINT properly
|
||||
# TODO: remove code duplication in plugins, probably use a common class?
|
||||
# TODO: add documentation / comments
|
||||
# TODO: add a dummy plugin to use as a starting point
|
||||
# TODO: interactivity support
|
||||
from sys import argv
|
||||
import argparse
|
||||
import configparser
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import plugins
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
DEFAULT_CONFIG = os.path.join(os.environ['HOME'], '.config/vdstatus/conf.ini')
|
||||
|
||||
|
||||
def parse_arguments(arguments=argv[1:]):
|
||||
def parse_arguments(arguments=sys.argv[1:]):
|
||||
desc = ('A simple i3status replacement, '
|
||||
'and more. Warning: WIP, may be broken.')
|
||||
p = argparse.ArgumentParser(description=desc)
|
||||
|
@ -69,11 +70,16 @@ def run_plugins(config_file=DEFAULT_CONFIG):
|
|||
|
||||
while True:
|
||||
outputs = list()
|
||||
for plugin in plugins_l:
|
||||
if not plugin.hide:
|
||||
outputs.append(plugin.status)
|
||||
print(format_outputs(outputs), flush=True)
|
||||
time.sleep(1)
|
||||
try:
|
||||
for plugin in plugins_l:
|
||||
if not plugin.hide:
|
||||
outputs.append(plugin.status)
|
||||
print(format_outputs(outputs), flush=True)
|
||||
time.sleep(1)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
for plugin in plugins_l:
|
||||
plugin.stop()
|
||||
sys.exit('stopping threads...')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue