mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 13:55:45 +02:00
parent
e3bebcc5b5
commit
7c65ee9703
@ -1105,25 +1105,29 @@ class NowPlayingSegment(object):
|
|||||||
now_playing = NowPlayingSegment()
|
now_playing = NowPlayingSegment()
|
||||||
|
|
||||||
|
|
||||||
if os.path.exists('/sys/class/power_supply/'):
|
try:
|
||||||
_linux_bat_fmt = '/sys/class/power_supply/{0}/capacity'
|
if os.path.exists('/sys/class/power_supply/'):
|
||||||
_linux_bat = 'BAT0'
|
_linux_bat_fmt = '/sys/class/power_supply/{0}/capacity'
|
||||||
if not os.path.exists(_linux_bat_fmt.format(_linux_bat)):
|
_linux_bat = 'BAT0'
|
||||||
_linux_bat = 'BAT1'
|
if not os.path.exists(_linux_bat_fmt.format(_linux_bat)):
|
||||||
if not os.path.exists(_linux_bat_fmt.format(_linux_bat)):
|
_linux_bat = 'BAT1'
|
||||||
raise NotImplementedError
|
if not os.path.exists(_linux_bat_fmt.format(_linux_bat)):
|
||||||
def _get_capacity(pl):
|
raise NotImplementedError
|
||||||
with open(_linux_bat_fmt.format(_linux_bat), 'r') as f:
|
def _get_capacity(pl):
|
||||||
return int(float(f.readline().split()[0]))
|
with open(_linux_bat_fmt.format(_linux_bat), 'r') as f:
|
||||||
elif os.path.exists('/usr/bin/pmset'):
|
return int(float(f.readline().split()[0]))
|
||||||
def _get_capacity(pl):
|
else:
|
||||||
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:
|
|
||||||
def _get_capacity(pl):
|
|
||||||
raise NotImplementedError
|
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:
|
||||||
|
def _get_capacity(pl):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='♥', empty_heart='♥'):
|
def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='♥', empty_heart='♥'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user