[wiki] [sites] wiki updated

From: <hg_AT_suckless.org>
Date: Sun, 3 Oct 2010 23:41:34 +0000 (UTC)

changeset: 630:b4de13282760
tag: tip
user: Wojciech Gac <wgac_AT_wp.pl>
date: Mon Oct 04 01:42:01 2010 +0200
files: wmii.suckless.org/code_snippets/python/battery_indicator.md wmii.suckless.org/code_snippets/python/memory_usage_indicator.md
description:
Added two items to python code snippets: memory and battery indicator for wmii.


diff -r 1cfbd0e0436f -r b4de13282760 wmii.suckless.org/code_snippets/python/battery_indicator.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wmii.suckless.org/code_snippets/python/battery_indicator.md Mon Oct 04 01:42:01 2010 +0200
_AT_@ -0,0 +1,81 @@
+Battery Indicator
+=================
+
+This is a simple battery indicator. Depending on the value of `from_acpi`
+it either uses the system command `acpi` or processes data from the `/proc`
+filesystem. To use it place the following code in your `wmiirc_local.py` file.
+Please note, that monitors in wmii are sorted
+alphabetically by their function names, so you might want to change the name as
+you see fit.
+
+The `trem` function is a helper function used to convert seconds to the format
+`hh:mm:ss`. `info_path` and `state_path` point to virtual files containing relevant
+information regarding the battery.
+
+
+`
+###
+import subprocess
+
+
+from_acpi = False
+#Read battery data from 'acpi' command.
+#If set to 'False' read data from /proc filesystem
+info_path = '/proc/acpi/battery/BAT0/info'
+state_path = '/proc/acpi/battery/BAT0/state'
+infostr = open(info_path)
+statestr = open(state_path)
+
+def trem(sec):
+ """Convert number of seconds to the format hh:mm:ss"""
+ h = sec / 3600
+ m = (sec - h * 3600) / 60
+ s = (sec - h * 3600 - m * 60)
+ return '%02d:%02d:%02d' % (h, m, s)
+###
+
+_AT_defmonitor
+def indicator(self):
+ if from_acpi:
+ inp = subprocess.Popen(['acpi'], shell = False, stdout = subprocess.PIPE)
+ out = inp.communicate()
+ return wmii.cache['normcolors'], out[0][:-1]
+ else:
+ info_raw = infostr.readlines()
+ state_raw = statestr.readlines()
+ infostr.seek(0)
+ statestr.seek(0)
+ info_list = []
+ state_list = []
+ for i in info_raw:
+ temp = i.split(':')
+ temp = map(str.strip, temp)
+ info_list.append(temp)
+ for i in state_raw:
+ temp = i.split(':')
+ temp = map(str.strip, temp)
+ state_list.append(temp)
+ info = dict(info_list)
+ state = dict(state_list)
+ if state['charging state'] == 'charging':
+ perc = float(state['remaining capacity'].split()[0])/\
+ float(info['last full capacity'].split()[0])*100
+ rem = int((float(info['last full capacity'].split()[0]) - \
+ float(state['remaining capacity'].split()[0]))/\
+ float(state['present rate'].split()[0])*3600)
+ res = 'Battery: Charging, %d%%, ' %perc\
+ + trem(rem) + ' remaining'
+ return wmii.cache['normcolors'], str(res)
+ elif state['charging state'] == 'discharging':
+ perc = float(state['remaining capacity'].split()[0])/\
+ float(info['last full capacity'].split()[0])*100
+ rem = int(float(state['remaining capacity'].split()[0])/\
+ float(state['present rate'].split()[0])*3600)
+ return wmii.cache['normcolors'], 'Battery: Discharging, %d%%, ' %perc\
+ + trem(rem) + ' remaining'
+ elif state['charging state'] == 'charged':
+ return wmii.cache['normcolors'], 'Battery: Fully Charged'
+ else:
+ return wmii.cache['focuscolors'], 'Battery: UNRECOGNIZED STATE!!!'
+`
+
diff -r 1cfbd0e0436f -r b4de13282760 wmii.suckless.org/code_snippets/python/memory_usage_indicator.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wmii.suckless.org/code_snippets/python/memory_usage_indicator.md Mon Oct 04 01:42:01 2010 +0200
_AT_@ -0,0 +1,29 @@
+Memory Usage Indicator
+======================
+
+This is a simple memory usage indicator based on information obtainable from
+the `free` system command.
+
+It was written to work with wmii-3.9 and higher. To use it you have to put it
+in your `wmiirc_local.py` file. Please note, that monitors in wmii are sorted
+alphabetically by their function names, so you might want to change the name as
+you see fit.
+
+
+`
+###
+import subprocess
+###
+
+_AT_defmonitor
+def fmem(self):
+ inp = subprocess.Popen(['free'], shell = False, stdout = subprocess.PIPE)
+ out = inp.communicate()
+ ram = int(out[0].splitlines()[2].split()[2])/1024
+ maxram = int(out[0].splitlines()[1].split()[1])/1024
+ swap = int(out[0].splitlines()[3].split()[2])/1024
+ maxswap = int(out[0].splitlines()[3].split()[1])/1024
+ return wmii.cache['normcolors'], 'RAM: ' + str(ram) + '/' + str(maxram) +\
+ ' MB' + ' | SWAP: ' + str(swap) + '/' + str(maxswap) + ' MB'
+`
+
Received on Mon Oct 04 2010 - 01:41:34 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:29 CEST