laptop

Tim Chase blinux.list at thechases.com
Thu Apr 3 02:36:34 UTC 2008


> If I get a .24 kernel will I get apm support or must I build it in?

I don't know what needs to be done to get APM support.  However, 
I've attached a fairly simple Python script that will extract the 
info you want from the /proc/acpi/battery/BAT*/{state,info} files.

Just "chmod ugo+x batt.py" after putting it somewhere in your 
path, and it will return a percentage along with what should be 
the state (charging or discharging).  It should also handle 
multiple batteries if you have them.  Hope this helps,

-tim




#!/usr/bin/env python
import os, re
from itertools import chain

acpi_battery_path = "/proc/acpi/battery/"
STATE_FILE = 'state'
INFO_FILE = 'info'

extract_mha_re = re.compile(r'^[^:]*:\s*(\d+).*')
def extract_mha(prefix, line):
     if line.startswith(prefix):
         m = extract_mha_re.match(line)
         if m:
             return int(m.group(1))
     return None

for battery in os.listdir(acpi_battery_path):
     if not battery.startswith("BAT"): continue
     battery_path = os.path.join(acpi_battery_path, battery)
     if not os.path.isdir(battery_path): continue
     current = max_cap = 0
     state = "Unknown"
     for line in chain(*map(
             lambda s: file(os.path.join(battery_path, s)),
             (STATE_FILE, INFO_FILE))):
         line = line.strip().lower()
         mha = extract_mha('remaining capacity:', line)
         if mha: current = mha
         mha = extract_mha('design capacity:', line)
         if mha: max_cap = mha
         if line.startswith("charging state:"):
             state = line.split(':', 1)[1].strip()
     print '%s: %i%% (%s)' % (
         battery, (current * 100) / max_cap, state)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: batt.py
Type: text/x-python
Size: 1012 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/blinux-list/attachments/20080402/33f5e3bd/attachment.py>


More information about the Blinux-list mailing list