diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-07 00:16:52 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-07 00:16:52 +0100 |
commit | 20c1782f7865b5f96b1650a65097a0e2bdd1241e (patch) | |
tree | 188a29f7e1bfa05a0a08a8d6f015f00a03d8e71e | |
parent | chase demo (diff) | |
download | xpybar-20c1782f7865b5f96b1650a65097a0e2bdd1241e.tar.gz xpybar-20c1782f7865b5f96b1650a65097a0e2bdd1241e.tar.bz2 xpybar-20c1782f7865b5f96b1650a65097a0e2bdd1241e.tar.xz |
fix and demo cpuonline
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | examples/plugins/cpuonline | 21 | ||||
-rw-r--r-- | src/plugins/cpuonline.py | 4 | ||||
-rw-r--r-- | src/util.py | 2 |
3 files changed, 25 insertions, 2 deletions
diff --git a/examples/plugins/cpuonline b/examples/plugins/cpuonline new file mode 100644 index 0000000..1796b22 --- /dev/null +++ b/examples/plugins/cpuonline @@ -0,0 +1,21 @@ +# -*- python -*- + +# A xpybar configuration example testing the features of plugins.chase + +import time +import threading + +from plugins.cpuonline import CPUOnline + + +OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True + + +def redraw(): + cpu = CPUOnline() + s = lambda cpus : ', '.join([str(i) for i in cpus]) + text = 'Online: %s │ Offline: %s │ Present: %s │ Possible: %s' + text %= s(cpu.online), s(cpu.offline), s(cpu.present), s(cpu.possible) + bar.clear() + bar.draw_coloured_text(0, 10, 0, 2, text) + diff --git a/src/plugins/cpuonline.py b/src/plugins/cpuonline.py index 75e8bed..8b42f66 100644 --- a/src/plugins/cpuonline.py +++ b/src/plugins/cpuonline.py @@ -45,8 +45,10 @@ class CPUOnline: for filename in ('offline', 'online', 'possible', 'present'): with open('/sys/devices/system/cpu/online', 'rb') as file: data.append(file.read()) + data = [x.decode('utf-8', 'replace').replace('\n', ' ').replace(',', ' ') for x in data] - data = [reduce(lambda x, y : x + y, map(expand, x.split(' '))) for x in data] + data = [map(expand, filter(lambda item : not item == '', x.split(' '))) for x in data] + data = [reduce(lambda x, y : x + y, list(x)) for x in data] (self.offline, self.online, self.possible, self.present) = data diff --git a/src/util.py b/src/util.py index 9c8c9d5..d42515b 100644 --- a/src/util.py +++ b/src/util.py @@ -98,7 +98,7 @@ def reduce(f, items): @return ¿E? The output ''' if len(items) < 2: - return items + return [] if len(items) == 0 else items[0] rc = items[0] for i in range(1, len(items)): rc = f(rc, items[i]) |