From 32f5abfb820a732e5d9b64249e58055b905c9c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 13 Feb 2024 21:33:21 +0100 Subject: [PATCH] powerprofilesctl: Use global variable to hold names and infaces --- src/powerprofilesctl.in | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/powerprofilesctl.in b/src/powerprofilesctl.in index 781b17e..3317b58 100755 --- a/src/powerprofilesctl.in +++ b/src/powerprofilesctl.in @@ -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