[wiki] [sites] wiki updated

From: <hg_AT_suckless.org>
Date: Fri, 8 Oct 2010 08:15:42 +0000 (UTC)

changeset: 631:eea55a0b9caa
tag: tip
user: Wojciech Gac <wgac_AT_wp.pl>
date: Fri Oct 08 10:16:08 2010 +0200
files: wmii.suckless.org/code_snippets/python/battery_indicator.md wmii.suckless.org/code_snippets/python/memory_usage_indicator.md
description:
Slight correction of the text formatting.


diff -r b4de13282760 -r eea55a0b9caa wmii.suckless.org/code_snippets/python/battery_indicator.md
--- a/wmii.suckless.org/code_snippets/python/battery_indicator.md Mon Oct 04 01:42:01 2010 +0200
+++ b/wmii.suckless.org/code_snippets/python/battery_indicator.md Fri Oct 08 10:16:08 2010 +0200
_AT_@ -12,70 +12,66 @@
 `hh:mm:ss`. `info_path` and `state_path` point to virtual files containing relevant
 information regarding the battery.
 
+ ###
+ import subprocess
 
-`
-###
-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)
+ ###
 
-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!!!'
-`
-
+ _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 b4de13282760 -r eea55a0b9caa wmii.suckless.org/code_snippets/python/memory_usage_indicator.md
--- a/wmii.suckless.org/code_snippets/python/memory_usage_indicator.md Mon Oct 04 01:42:01 2010 +0200
+++ b/wmii.suckless.org/code_snippets/python/memory_usage_indicator.md Fri Oct 08 10:16:08 2010 +0200
_AT_@ -9,21 +9,18 @@
 alphabetically by their function names, so you might want to change the name as
 you see fit.
 
+ ###
+ import subprocess
+ ###
 
-`
-###
-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'
 
-_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 Fri Oct 08 2010 - 10:15:42 CEST

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