Added OSX battery support

This commit is contained in:
Joshua Perry 2014-02-07 11:10:43 -07:00 committed by ZyX
parent b5c14553a9
commit 9accbdd9ef

View File

@ -1079,6 +1079,13 @@ if os.path.exists('/sys/class/power_supply/BAT0/capacity'):
def _get_capacity():
with open('/sys/class/power_supply/BAT0/capacity', 'r') as f:
return int(float(f.readline().split()[0]))
elif os.path.exists('/usr/bin/pmset'):
def _get_capacity():
import re
import subprocess
battery_summary = subprocess.check_output(['pmset', '-g', 'batt']).decode('utf8')
batt_percent = re.search(r'\d+%', battery_summary).group(0)
return int(batt_percent.replace('%', ''))
else:
def _get_capacity():
raise NotImplementedError