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 105 by iggykoopa on Wed 21st Jan 05:01 and
original post 104 by iggykoopa on Wed 21st Jan 04:47
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")
7+
home = os.getenv("HOME")
8+
path = home + "/scripts/draw"
79
if batteries:
810
    batInfo = open("/proc/acpi/battery/%s/state" % (batteries[0],))
911
    voltage = 0.0
1012
    watts_drawn = 0.0
1113
    amperes_drawn = 0.0
1214
    seconds = 0.0
1315
    available = True
1416
    for line in batInfo:
1517
        if "charging state" in line:
1618
            if not "discharging" in line:
1719
                available = False
1820
        if "present voltage" in line:
1921
            voltage = float(line.split()[2]) / 1000.0
2022
        if "present rate" in line and "mW" in line:
2123
            watts_drawn = float(line.split()[2]) / 1000.0
2224
        if "present rate" in line and "mA" in line:
2325
            amperes_drawn = float(line.split()[2]) / 1000.0
2426
        if "remaining capacity" in line:
2527
            capacity = float(line.split()[2])
2628
    if watts_drawn == 0.0 and amperes_drawn == 0.0:
27-
        if os.path.exists("draw"):
29+
        if os.path.exists(path):
28-
            draw_file = open("draw")
30+
            draw_file = open(path)
2931
            draw = draw_file.readline()
3032
            if draw:
3133
                draw = float(draw)
3234
                seconds = float(draw_file.readline())
3335
                if draw == capacity:
3436
                    seconds = seconds + 1
3537
                    amperes_drawn = float(draw_file.readline())
3638
                else:
3739
                    draw = draw - capacity
3840
                    amperes_drawn = draw / seconds * 3600.0 / 1000.0
3941
                    seconds = 0.0
40-
        draw = open("draw","w")
42+
        draw = open(path,"w")
4143
        draw.write(str(capacity) + "\n" + str(seconds) + "\n" + str(amperes_drawn))
4244
    rate = watts_drawn + voltage * amperes_drawn
4345
    if available:
4446
        print '%.2f'%(rate)
4547
    else:
4648
        print "No Data"
47-
        if os.path.exists("draw"):
49+
        if os.path.exists(path):
48-
            os.remove("draw")
50+
            os.remove(path)
4951
else:
5052
    print "No Data"
51-
    if os.path.exists("draw"):
53+
    if os.path.exists(path):
52-
        os.remove("draw")
54+
        os.remove(path)

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me