a fully functional version
This commit is contained in:
parent
c272a21aa7
commit
9bcfcaf177
7 changed files with 135 additions and 33 deletions
33
plugins/batt.py
Normal file
33
plugins/batt.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import threading
|
||||
import time
|
||||
|
||||
|
||||
BATTERY_DIR = '/sys/class/power_supply/BAT0/'
|
||||
|
||||
|
||||
class PluginThread(threading.Thread):
|
||||
def __init__(self, section, config, thread_id):
|
||||
threading.Thread.__init__(self)
|
||||
self.threadID = thread_id
|
||||
self.status = dict()
|
||||
if config.has_option(section, 'color'):
|
||||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = 1
|
||||
|
||||
def main(self):
|
||||
with open(BATTERY_DIR + 'capacity', 'r') as capacity, \
|
||||
open(BATTERY_DIR + 'status', 'r') as status:
|
||||
batt_stat = status.read().strip()
|
||||
batt_capacity = capacity.read().strip()
|
||||
if batt_stat != 'Discharging':
|
||||
batt_stat = '\u2191'
|
||||
else:
|
||||
batt_stat = '\u2193'
|
||||
batt = 'BAT: ' + batt_capacity + '% ' + batt_stat
|
||||
|
||||
self.status['full_text'] = batt
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
|
@ -6,13 +6,16 @@ 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')
|
||||
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')
|
||||
self.freq = 1
|
||||
|
||||
def main(self):
|
||||
self.status['full_text'] = time.strftime(self.date_format)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.status['full_text'] = time.strftime(self.date_format)
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
|
|
25
plugins/mem.py
Normal file
25
plugins/mem.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
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()
|
||||
if config.has_option(section, 'color'):
|
||||
self.status['color'] = config.get(section, 'color')
|
||||
self.freq = 1
|
||||
|
||||
def main(self):
|
||||
mem_stat = psutil.virtual_memory()
|
||||
mem_percentage = round(100.0 - mem_stat.percent, 2)
|
||||
mem_available = round(mem_stat.available / 2**30, 2)
|
||||
mem = 'RAM: ' + str(mem_percentage) + '% (' + str(mem_available) + 'G)'
|
||||
self.status['full_text'] = mem
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
|
@ -10,25 +10,34 @@ class PluginThread(threading.Thread):
|
|||
self.threadID = thread_id
|
||||
self.hosts = config.get(section, 'hosts').split(',')
|
||||
self.title = config.get(section, 'title')
|
||||
if config.has_option(section, 'colors'):
|
||||
self.colors = config.get(section, 'colors').split(',')
|
||||
else:
|
||||
self.colors = None
|
||||
self.timeout = config.get(section, 'timeout', fallback='150')
|
||||
self.status = dict()
|
||||
self.freq = 5
|
||||
self.freq = config.getint(section, 'freq', fallback=5)
|
||||
self.format_status('n/a')
|
||||
|
||||
def format_status(self, state):
|
||||
self.status['full_text'] = self.title + ': ' + state
|
||||
if self.colors is not None:
|
||||
if state == 'on':
|
||||
self.status['color'] = self.colors[0]
|
||||
else:
|
||||
self.status['color'] = self.colors[1]
|
||||
|
||||
def main(self):
|
||||
random.shuffle(self.hosts)
|
||||
for host in self.hosts:
|
||||
fping = 'fping -q -c1 -t' + self.timeout + ' ' + host + ' &>/dev/null'
|
||||
response = os.system(fping)
|
||||
if response == 0:
|
||||
self.format_status('on')
|
||||
break
|
||||
self.format_status('off')
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
random.shuffle(self.hosts)
|
||||
try:
|
||||
for host in self.hosts:
|
||||
fping = 'fping -q -c1 -t100 ' + host + ' &>/dev/null'
|
||||
response = os.system(fping)
|
||||
if response == 0:
|
||||
self.format_status('on')
|
||||
break
|
||||
self.format_status('off')
|
||||
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
break
|
||||
self.main()
|
||||
time.sleep(self.freq)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue