CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Difference between
modified post 1968 by Anonymous on Sat 5th Jan 01:50 and
original post 246 by iggykoopa on Sun 17th May 21:23
Show old version | new version | both versions

    
11
#!/usr/bin/env python
33
import os
55
rate = 0.0
66
batteries = os.listdir("/proc/acpi/battery")
77
home = os.getenv("HOME")
88
path = "/tmp/draw"
99
if batteries:
1010
    batInfo = open("/proc/acpi/battery/%s/state" % (batteries[0],))
1111
    voltage = 0.0
1212
    watts_drawn = 0.0
1313
    amperes_drawn = 0.0
1414
    seconds = 0.0
1515
    available = True
1616
    for line in batInfo:
1717
        if "charging state" in line:
1818
            if not "discharging" in line:
1919
                available = False
2020
        if "present voltage" in line:
2121
            voltage = float(line.split()[2]) / 1000.0
2222
        if "present rate" in line and "mW" in line:
2323
            watts_drawn = float(line.split()[2]) / 1000.0
2424
        if "present rate" in line and "mA" in line:
2525
            amperes_drawn = float(line.split()[2]) / 1000.0
2626
        if "remaining capacity" in line:
2727
            capacity = float(line.split()[2])
2828
    if watts_drawn == 0.0 and amperes_drawn == 0.0:
2929
        if os.path.exists(path):
3030
            draw_file = open(path)
3131
            draw = draw_file.readline()
3232
            if draw:
3333
                draw = float(draw)
3434
                seconds = float(draw_file.readline())
3535
                if draw == capacity:
3636
                    seconds = seconds + 1
3737
                    amperes_drawn = float(draw_file.readline())
3838
                else:
3939
                    draw = draw - capacity
4040
                    amperes_drawn = draw / seconds * 3600.0 / 1000.0
4141
                    seconds = 0.0
4242
        draw = open(path,"w")
4343
        draw.write(str(capacity) + "\n" + str(seconds) + "\n" + str(amperes_drawn))
4444
    rate = watts_drawn + voltage * amperes_drawn
4545
    if available:
4646
        if rate < 1.0:
4747
            print "Gathering Data"
4848
        else:
4949
            print '%.2f'%(rate)
5050
    else:
5151
        print "No Data"
5252
        if os.path.exists(path):
5353
            os.remove(path)
5454
else:
5555
    print "No Data"
5656
    if os.path.exists(path):
5757
        os.remove(path)

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me