From a54415aa2c34a3e31dba6c621fdb4b441b5764f9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 16 Jan 2020 11:20:57 +0000 Subject: [PATCH] malcontent-client: Improve specificity of exit statuses Add a couple of missing exit statuses (and document them) and convert Malcontent errors to exit statuses more specifically. Signed-off-by: Philip Withnall --- malcontent-client/docs/malcontent-client.8 | 9 +++++++++ malcontent-client/malcontent-client.py | 23 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/malcontent-client/docs/malcontent-client.8 b/malcontent-client/docs/malcontent-client.8 index 3f765ef..917adb7 100644 --- a/malcontent-client/docs/malcontent-client.8 +++ b/malcontent-client/docs/malcontent-client.8 @@ -102,6 +102,15 @@ The current user was not authorized to query the app filter for the given user. If running the \fBcheck\-app\-filter\fP command, the given path, content type or flatpak ref was \fInot\fP allowed for the given user. .\" +.IP "4" 4 +.IX Item "4" +Malcontent is disabled at the system level, and hence parental controls are +not enabled or enforced. +.\" +.IP "5" 4 +.IX Item "5" +An operation failed and no more specific error information is available. +.\" .SH BUGS .IX Header "BUGS" .\" diff --git a/malcontent-client/malcontent-client.py b/malcontent-client/malcontent-client.py index c9a2e15..21e0377 100644 --- a/malcontent-client/malcontent-client.py +++ b/malcontent-client/malcontent-client.py @@ -30,6 +30,25 @@ EXIT_SUCCESS = 0 EXIT_INVALID_OPTION = 1 EXIT_PERMISSION_DENIED = 2 EXIT_PATH_NOT_ALLOWED = 3 +EXIT_DISABLED = 4 +EXIT_FAILED = 5 + + +def __manager_error_to_exit_code(error): + if error.matches(Malcontent.manager_error_quark(), + Malcontent.ManagerError.INVALID_USER): + return EXIT_INVALID_OPTION + elif error.matches(Malcontent.manager_error_quark(), + Malcontent.ManagerError.PERMISSION_DENIED): + return EXIT_PERMISSION_DENIED + elif error.matches(Malcontent.manager_error_quark(), + Malcontent.ManagerError.INVALID_DATA): + return EXIT_INVALID_OPTION + elif error.matches(Malcontent.manager_error_quark(), + Malcontent.ManagerError.DISABLED): + return EXIT_DISABLED + + return EXIT_FAILED def __get_app_filter(user_id, interactive): @@ -57,7 +76,7 @@ def __get_app_filter_or_error(user_id, interactive): except GLib.Error as e: print('Error getting app filter for user {}: {}'.format( user_id, e.message), file=sys.stderr) - raise SystemExit(EXIT_PERMISSION_DENIED) + raise SystemExit(__manager_error_to_exit_code(e)) def __set_app_filter(user_id, app_filter, interactive): @@ -85,7 +104,7 @@ def __set_app_filter_or_error(user_id, app_filter, interactive): except GLib.Error as e: print('Error setting app filter for user {}: {}'.format( user_id, e.message), file=sys.stderr) - raise SystemExit(EXIT_PERMISSION_DENIED) + raise SystemExit(__manager_error_to_exit_code(e)) def __lookup_user_id(user_id_or_username):