[orca-list] script for battery information
- From: Jonathan Chacón <jonathan chacon telefonica net>
- To: orca-list gnome org
- Subject: [orca-list] script for battery information
- Date: Sun, 10 Aug 2008 07:17:28 +0200
Hello everybody,
I wrote a script to get charge battery information. It uses acpi
tecnology...
I hope this script will be fine
here is the script:
import os
def sayBattery(script, inputEvent=None):
acpiBatteryPath = "/proc/acpi/battery" # path for batteries
batteries = os.listdir(acpiBatteryPath) # gets all batteries in the PC
if len(batteries) > 0 : # there is battery support
for b in batteries:
# gets info about the battery
pathFile = acpiBatteryPath + "/" + b + "/"
infoBatteryFile = file(pathFile + "info", "r") # opens info battery
if infoBatteryFile.readline().split()[1] == "yes":
infoBatteryFile.readline() # jumps a line
batteryMaxCap = float (infoBatteryFile.readline().split()[3]) # gets
max capacity
# gets status battery
statusBatteryFile = file(pathFile + "state", "r") # jumps to battery
charge
statusBatteryFile.readline()
statusBatteryFile.readline()
chargingStatus = statusBatteryFile.readline().split()[2]
statusBatteryFile.readline()
batteryCharge = int
(float(statusBatteryFile.readline().split()[2])/batteryMaxCap*100)
statusBatteryFile.close()
# make the string result
strResult = str(batteryCharge) + "% "
# add charging status (charging - charged )
if chargingStatus == "charged": strResult += " charged "
if chargingStatus == "charging": strResult += " charging "
else: strResult = "Battery not found" # battery not present
infoBatteryFile.close()
# for two or more batteries
if len(batteries) > 1: strResult = b + ":" + strResult
else: strResult = "No battery support"
speech.speak(strResult)
return true
regards
Jonathan ChacÃn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]