mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 05:46:01 +02:00
Added OSX battery support
This commit is contained in:
parent
b5c14553a9
commit
9accbdd9ef
@ -1079,6 +1079,13 @@ if os.path.exists('/sys/class/power_supply/BAT0/capacity'):
|
|||||||
def _get_capacity():
|
def _get_capacity():
|
||||||
with open('/sys/class/power_supply/BAT0/capacity', 'r') as f:
|
with open('/sys/class/power_supply/BAT0/capacity', 'r') as f:
|
||||||
return int(float(f.readline().split()[0]))
|
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:
|
else:
|
||||||
def _get_capacity():
|
def _get_capacity():
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Loading…
x
Reference in New Issue
Block a user