mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-06 14:58:01 +02:00
powerprofilesctl: Use global variable to hold names and infaces
This commit is contained in:
parent
3b29b0e52b
commit
32f5abfb82
1 changed files with 11 additions and 11 deletions
|
|
@ -7,6 +7,10 @@ from gi.repository import Gio, GLib
|
|||
|
||||
VERSION = '@VERSION@'
|
||||
|
||||
PP_NAME = 'org.freedesktop.UPower.PowerProfiles'
|
||||
PP_PATH = '/org/freedesktop/UPower/PowerProfiles'
|
||||
PP_IFACE = 'org.freedesktop.UPower.PowerProfiles'
|
||||
|
||||
def usage_main():
|
||||
print('Usage:')
|
||||
print(' powerprofilesctl COMMAND [ARGS…]')
|
||||
|
|
@ -94,23 +98,21 @@ def get_proxy():
|
|||
try:
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
'/org/freedesktop/UPower/PowerProfiles',
|
||||
'org.freedesktop.DBus.Properties', None)
|
||||
PP_NAME, PP_PATH, PP_IFACE, None)
|
||||
except:
|
||||
raise
|
||||
return proxy
|
||||
|
||||
def _get():
|
||||
proxy = get_proxy()
|
||||
profile = proxy.Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'ActiveProfile')
|
||||
profile = proxy.Get('(ss)', PP_IFACE, 'ActiveProfile')
|
||||
print(profile)
|
||||
|
||||
def _set(profile):
|
||||
try:
|
||||
proxy = get_proxy()
|
||||
proxy.Set('(ssv)',
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
PP_IFACE,
|
||||
'ActiveProfile',
|
||||
GLib.Variant.new_string(profile))
|
||||
except:
|
||||
|
|
@ -124,7 +126,7 @@ def get_profiles_property(prop):
|
|||
|
||||
profiles = None
|
||||
try:
|
||||
profiles = proxy.Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', prop)
|
||||
profiles = proxy.Get('(ss)', PP_IFACE, prop)
|
||||
except:
|
||||
raise
|
||||
return profiles
|
||||
|
|
@ -132,9 +134,9 @@ def get_profiles_property(prop):
|
|||
def _list():
|
||||
try:
|
||||
profiles = get_profiles_property('Profiles')
|
||||
reason = get_proxy().Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'PerformanceDegraded')
|
||||
reason = get_proxy().Get('(ss)', PP_IFACE, 'PerformanceDegraded')
|
||||
degraded = reason != ''
|
||||
active = get_proxy().Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'ActiveProfile')
|
||||
active = get_proxy().Get('(ss)', PP_IFACE, 'ActiveProfile')
|
||||
except:
|
||||
raise
|
||||
|
||||
|
|
@ -174,9 +176,7 @@ def _launch(args, profile, appid, reason):
|
|||
try:
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
'/org/freedesktop/UPower/PowerProfiles',
|
||||
'org.freedesktop.UPower.PowerProfiles', None)
|
||||
PP_NAME, PP_PATH, PP_IFACE, None)
|
||||
except:
|
||||
raise
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue