eos-parental-controls-client: Use synchronous methods

This should not introduce any functional changes, but does simplify the
code.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://phabricator.endlessm.com/T24024
This commit is contained in:
Philip Withnall 2018-10-31 11:04:40 +00:00
parent 3b4dbf7019
commit 72812d2709
1 changed files with 4 additions and 42 deletions

View File

@ -37,28 +37,9 @@ def __get_app_filter(user_id, interactive):
If `interactive` is `True`, interactive polkit authorisation dialogues will If `interactive` is `True`, interactive polkit authorisation dialogues will
be allowed. An exception will be raised on failure.""" be allowed. An exception will be raised on failure."""
app_filter = None return EosParentalControls.get_app_filter(
exception = None
def __get_cb(obj, result, user_data):
nonlocal app_filter, exception
try:
app_filter = EosParentalControls.get_app_filter_finish(result)
except Exception as e:
exception = e
EosParentalControls.get_app_filter_async(
connection=None, user_id=user_id, connection=None, user_id=user_id,
allow_interactive_authorization=interactive, cancellable=None, allow_interactive_authorization=interactive, cancellable=None)
callback=__get_cb, user_data=None)
context = GLib.MainContext.default()
while not app_filter and not exception:
context.iteration(True)
if exception:
raise exception
return app_filter
def __get_app_filter_or_error(user_id, interactive): def __get_app_filter_or_error(user_id, interactive):
@ -77,28 +58,9 @@ def __set_app_filter(user_id, app_filter, interactive):
If `interactive` is `True`, interactive polkit authorisation dialogues will If `interactive` is `True`, interactive polkit authorisation dialogues will
be allowed. An exception will be raised on failure.""" be allowed. An exception will be raised on failure."""
finished = False EosParentalControls.set_app_filter(
exception = None
def __set_cb(obj, result, user_data):
nonlocal finished, exception
try:
EosParentalControls.set_app_filter_finish(result)
finished = True
except Exception as e:
exception = e
EosParentalControls.set_app_filter_async(
connection=None, user_id=user_id, app_filter=app_filter, connection=None, user_id=user_id, app_filter=app_filter,
allow_interactive_authorization=interactive, cancellable=None, allow_interactive_authorization=interactive, cancellable=None)
callback=__set_cb, user_data=None)
context = GLib.MainContext.default()
while not finished and not exception:
context.iteration(True)
if exception:
raise exception
def __set_app_filter_or_error(user_id, app_filter, interactive): def __set_app_filter_or_error(user_id, app_filter, interactive):