mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-08 01:58:06 +02:00
Add support for running powerprofilesctl with legacy interface
This will allow checking the behavior of the old interface remains compatible.
This commit is contained in:
parent
493818a7e2
commit
90226bf0d8
1 changed files with 37 additions and 21 deletions
|
|
@ -8,14 +8,24 @@ from gi.repository import Gio, GLib
|
|||
|
||||
PP_NAME = "org.freedesktop.UPower.PowerProfiles"
|
||||
PP_PATH = "/org/freedesktop/UPower/PowerProfiles"
|
||||
PP_IFACE = "org.freedesktop.UPower.PowerProfiles"
|
||||
PP_IFACE = PP_NAME
|
||||
PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"
|
||||
|
||||
LEGACY_PP_NAME = "net.hadess.PowerProfiles"
|
||||
LEGACY_PP_PATH = "/net/hadess/PowerProfiles"
|
||||
LEGACY_PP_IFACE = LEGACY_PP_NAME
|
||||
|
||||
def get_proxy():
|
||||
|
||||
def get_iface(legacy):
|
||||
if legacy:
|
||||
return LEGACY_PP_NAME, LEGACY_PP_PATH, LEGACY_PP_IFACE
|
||||
return PP_NAME, PP_PATH, PP_IFACE
|
||||
|
||||
|
||||
def get_proxy(name, path):
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
return Gio.DBusProxy.new_sync(
|
||||
bus, Gio.DBusProxyFlags.NONE, None, PP_NAME, PP_PATH, PROPERTIES_IFACE, None
|
||||
bus, Gio.DBusProxyFlags.NONE, None, name, path, PROPERTIES_IFACE, None
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -39,8 +49,9 @@ def command(func):
|
|||
def _version(args): # pylint: disable=unused-argument
|
||||
client_version = "@VERSION@"
|
||||
try:
|
||||
proxy = get_proxy()
|
||||
daemon_ver = proxy.Get("(ss)", PP_IFACE, "Version")
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = get_proxy(name, path)
|
||||
daemon_ver = proxy.Get("(ss)", iface, "Version")
|
||||
except GLib.Error:
|
||||
daemon_ver = "unknown"
|
||||
print(f"client: {client_version}\ndaemon: {daemon_ver}")
|
||||
|
|
@ -48,30 +59,27 @@ def _version(args): # pylint: disable=unused-argument
|
|||
|
||||
@command
|
||||
def _get(args): # pylint: disable=unused-argument
|
||||
proxy = get_proxy()
|
||||
profile = proxy.Get("(ss)", PP_IFACE, "ActiveProfile")
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = get_proxy(name, path)
|
||||
profile = proxy.Get("(ss)", iface, "ActiveProfile")
|
||||
print(profile)
|
||||
|
||||
|
||||
@command
|
||||
def _set(args):
|
||||
proxy = get_proxy()
|
||||
proxy.Set(
|
||||
"(ssv)", PP_IFACE, "ActiveProfile", GLib.Variant.new_string(args.profile[0])
|
||||
)
|
||||
|
||||
|
||||
def get_profiles_property(prop):
|
||||
proxy = get_proxy()
|
||||
return proxy.Get("(ss)", PP_IFACE, prop)
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = get_proxy(name, path)
|
||||
proxy.Set("(ssv)", iface, "ActiveProfile", GLib.Variant.new_string(args.profile[0]))
|
||||
|
||||
|
||||
@command
|
||||
def _list(args): # pylint: disable=unused-argument
|
||||
profiles = get_profiles_property("Profiles")
|
||||
reason = get_proxy().Get("(ss)", PP_IFACE, "PerformanceDegraded")
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = get_proxy(name, path)
|
||||
profiles = proxy.Get("(ss)", iface, "Profiles")
|
||||
reason = proxy.Get("(ss)", iface, "PerformanceDegraded")
|
||||
degraded = reason != ""
|
||||
active = get_proxy().Get("(ss)", PP_IFACE, "ActiveProfile")
|
||||
active = proxy.Get("(ss)", iface, "ActiveProfile")
|
||||
|
||||
index = 0
|
||||
for profile in reversed(profiles):
|
||||
|
|
@ -91,7 +99,9 @@ def _list(args): # pylint: disable=unused-argument
|
|||
|
||||
@command
|
||||
def _list_holds(args): # pylint: disable=unused-argument
|
||||
holds = get_profiles_property("ActiveProfileHolds")
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = get_proxy(name, path)
|
||||
holds = proxy.Get("(ss)", iface, "ActiveProfileHolds")
|
||||
|
||||
index = 0
|
||||
for hold in holds:
|
||||
|
|
@ -119,8 +129,9 @@ def _launch(args):
|
|||
reason = f"Running {args.appid}"
|
||||
ret = 0
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
name, path, iface = get_iface(args.legacy)
|
||||
proxy = Gio.DBusProxy.new_sync(
|
||||
bus, Gio.DBusProxyFlags.NONE, None, PP_NAME, PP_PATH, PP_IFACE, None
|
||||
bus, Gio.DBusProxyFlags.NONE, None, name, path, iface, None
|
||||
)
|
||||
cookie = proxy.HoldProfile("(sss)", profile, reason, appid)
|
||||
|
||||
|
|
@ -146,6 +157,11 @@ def get_parser():
|
|||
parser = argparse.ArgumentParser(
|
||||
epilog="Use “powerprofilesctl COMMAND --help” to get detailed help for individual commands",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--legacy",
|
||||
action="store_true",
|
||||
help="Use legacy interface to communicate with daemon.",
|
||||
)
|
||||
subparsers = parser.add_subparsers(help="Individual command help", dest="command")
|
||||
parser_list = subparsers.add_parser("list", help="List available power profiles")
|
||||
parser_list.set_defaults(func=_list)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue