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

Posted by thapsanghotmailc on Thu 21st May 15:00 (modification of post by iggykoopa view diff)
diff | download | new post

  1. #!/usr/bin/env python
  2.  
  3. import os
  4.  
  5. rate = 0.0
  6. batteries = os.listdir("/proc/acpi/battery")
  7. home = os.getenv("HOME")
  8. path = "/tmp/draw"
  9. if batteries:
  10.     batInfo = open("/proc/acpi/battery/%s/state" % (batteries[0],))
  11.     voltage = 0.0
  12.     watts_drawn = 0.0
  13.     amperes_drawn = 0.0
  14.     seconds = 0.0
  15.     available = True
  16.     for line in batInfo:
  17.         if "charging state" in line:
  18.             if not "discharging" in line:
  19.                 available = False
  20.         if "present voltage" in line:
  21.             voltage = float(line.split()[2]) / 1000.0
  22.         if "present rate" in line and "mW" in line:
  23.             watts_drawn = float(line.split()[2]) / 1000.0
  24.         if "present rate" in line and "mA" in line:
  25.             amperes_drawn = float(line.split()[2]) / 1000.0
  26.         if "remaining capacity" in line:
  27.             capacity = float(line.split()[2])
  28.     if watts_drawn == 0.0 and amperes_drawn == 0.0:
  29.         if os.path.exists(path):
  30.             draw_file = open(path)
  31.             draw = draw_file.readline()
  32.             if draw:
  33.                 draw = float(draw)
  34.                 seconds = float(draw_file.readline())
  35.                 if draw == capacity:
  36.                     seconds = seconds + 1
  37.                     amperes_drawn = float(draw_file.readline())
  38.                 else:
  39.                     draw = draw - capacity
  40.                     amperes_drawn = draw / seconds * 3600.0 / 1000.0
  41.                     seconds = 0.0
  42.         draw = open(path,"w")
  43.         draw.write(str(capacity) + "\n" + str(seconds) + "\n" + str(amperes_drawn))
  44.     rate = watts_drawn + voltage * amperes_drawn
  45.     if available:
  46.         if rate < 1.0:
  47.             print "Gathering Data"
  48.         else:
  49.             print '%.2f'%(rate)
  50.     else:
  51.         print "No Data"
  52.         if os.path.exists(path):
  53.             os.remove(path)
  54. else:
  55.     print "No Data"
  56.     if os.path.exists(path):
  57.         os.remove(path)

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me