mirror of
https://github.com/powerline/powerline.git
synced 2025-07-25 14:54:54 +02:00
parent
e3bebcc5b5
commit
7c65ee9703
@ -1105,7 +1105,8 @@ class NowPlayingSegment(object):
|
||||
now_playing = NowPlayingSegment()
|
||||
|
||||
|
||||
if os.path.exists('/sys/class/power_supply/'):
|
||||
try:
|
||||
if os.path.exists('/sys/class/power_supply/'):
|
||||
_linux_bat_fmt = '/sys/class/power_supply/{0}/capacity'
|
||||
_linux_bat = 'BAT0'
|
||||
if not os.path.exists(_linux_bat_fmt.format(_linux_bat)):
|
||||
@ -1115,13 +1116,16 @@ if os.path.exists('/sys/class/power_supply/'):
|
||||
def _get_capacity(pl):
|
||||
with open(_linux_bat_fmt.format(_linux_bat), 'r') as f:
|
||||
return int(float(f.readline().split()[0]))
|
||||
elif os.path.exists('/usr/bin/pmset'):
|
||||
else:
|
||||
raise NotImplementedError
|
||||
except NotImplementedError:
|
||||
if os.path.exists('/usr/bin/pmset'):
|
||||
def _get_capacity(pl):
|
||||
import re
|
||||
battery_summary = run_cmd(pl, ['pmset', '-g', 'batt'])
|
||||
battery_percent = re.search(r'(\d+)%', battery_summary).group(1)
|
||||
return int(battery_percent)
|
||||
else:
|
||||
else:
|
||||
def _get_capacity(pl):
|
||||
raise NotImplementedError
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user