mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-01 09:08:02 +02:00
main: Error out on D-Bus communication errors
The bug reporting tool in Fedora, in its infinite wisdom, considers innocuous exceptions that occur when system daemons aren't running to be bug report worthy. Catch all the D-Bus communication errors, print an error message detailing the problem and exit with a return value of 1 when they occur instead of printing an exception. See: https://bugzilla.redhat.com/show_bug.cgi?id=2019536 https://bugzilla.redhat.com/show_bug.cgi?id=2020251 https://bugzilla.redhat.com/show_bug.cgi?id=2020941
This commit is contained in:
parent
0aef9d6a2f
commit
fd1664dfe2
2 changed files with 32 additions and 14 deletions
|
|
@ -44,7 +44,7 @@ add_global_arguments(common_cflags, language: 'c')
|
|||
|
||||
if get_option('pylint')
|
||||
pylint = find_program('pylint-3', 'pylint3', 'pylint', required: true)
|
||||
pylint_flags = ['-d', 'C0116', '-d', 'C0114', '-d', 'W0707']
|
||||
pylint_flags = ['-d', 'C0116', '-d', 'C0114', '-d', 'W0707', '-d', 'W0706' ]
|
||||
endif
|
||||
xmllint = find_program('xmllint', required: false)
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ def get_proxy():
|
|||
'/net/hadess/PowerProfiles',
|
||||
'org.freedesktop.DBus.Properties', None)
|
||||
except:
|
||||
raise SystemError
|
||||
raise
|
||||
return proxy
|
||||
|
||||
def _get():
|
||||
|
|
@ -117,13 +117,13 @@ def get_profiles_property(prop):
|
|||
try:
|
||||
proxy = get_proxy()
|
||||
except:
|
||||
raise SystemError
|
||||
raise
|
||||
|
||||
profiles = None
|
||||
try:
|
||||
profiles = proxy.Get('(ss)', 'net.hadess.PowerProfiles', prop)
|
||||
except:
|
||||
raise ReferenceError
|
||||
raise
|
||||
else:
|
||||
return profiles
|
||||
|
||||
|
|
@ -134,8 +134,7 @@ def _list():
|
|||
degraded = (reason != '')
|
||||
active = get_proxy().Get('(ss)', 'net.hadess.PowerProfiles', 'ActiveProfile')
|
||||
except:
|
||||
print("Couldn\'t get Profiles: ", sys.exc_info()[0])
|
||||
raise SystemError
|
||||
raise
|
||||
else:
|
||||
index = 0
|
||||
for profile in reversed(profiles):
|
||||
|
|
@ -152,8 +151,7 @@ def _list_holds():
|
|||
try:
|
||||
holds = get_profiles_property('ActiveProfileHolds')
|
||||
except:
|
||||
# print("Couldn\'t get ActiveProfileHolds: ", sys.exc_info()[0])
|
||||
raise SystemError
|
||||
raise
|
||||
else:
|
||||
index = 0
|
||||
for hold in holds:
|
||||
|
|
@ -173,7 +171,7 @@ def _launch(args, profile, appid, reason):
|
|||
'/net/hadess/PowerProfiles',
|
||||
'net.hadess.PowerProfiles', None)
|
||||
except:
|
||||
raise SystemError
|
||||
raise
|
||||
|
||||
cookie = proxy.HoldProfile('(sss)', profile, reason, appid)
|
||||
|
||||
|
|
@ -208,16 +206,32 @@ def main(): # pylint: disable=too-many-branches, disable=too-many-statements
|
|||
elif command == 'version':
|
||||
version()
|
||||
elif command == 'get':
|
||||
_get()
|
||||
try:
|
||||
_get()
|
||||
except GLib.Error as error:
|
||||
sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
|
||||
sys.exit(1)
|
||||
elif command == 'set':
|
||||
if len(args) != 1:
|
||||
usage_set()
|
||||
sys.exit(1)
|
||||
_set(args[0])
|
||||
try:
|
||||
_set(args[0])
|
||||
except GLib.Error as error:
|
||||
sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
|
||||
sys.exit(1)
|
||||
elif command == 'list':
|
||||
_list()
|
||||
try:
|
||||
_list()
|
||||
except GLib.Error as error:
|
||||
sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
|
||||
sys.exit(1)
|
||||
elif command == 'list-holds':
|
||||
_list_holds()
|
||||
try:
|
||||
_list_holds()
|
||||
except GLib.Error as error:
|
||||
sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
|
||||
sys.exit(1)
|
||||
elif command == 'launch':
|
||||
if len(args) == 0:
|
||||
sys.exit(0)
|
||||
|
|
@ -256,7 +270,11 @@ def main(): # pylint: disable=too-many-branches, disable=too-many-statements
|
|||
reason = 'Running ' + appid
|
||||
if not profile:
|
||||
profile = 'performance'
|
||||
_launch(args, profile, appid, reason)
|
||||
try:
|
||||
_launch(args, profile, appid, reason)
|
||||
except GLib.Error as error:
|
||||
sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue