eos-parental-controls-client: Add OARS filter support

This basic support will return the value of a given OARS section to the
caller.

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

https://phabricator.endlessm.com/T23999
This commit is contained in:
Philip Withnall 2018-10-09 23:25:39 +13:00
parent 6cc9b9bb27
commit 8b2115a801
1 changed files with 40 additions and 0 deletions

View File

@ -95,6 +95,23 @@ def __lookup_user_id_or_error(user):
raise SystemExit(EXIT_INVALID_OPTION)
def __oars_value_to_string(value):
"""Convert an EosParentalControls.AppFilterOarsValue to a human-readable
string."""
mapping = {
EosParentalControls.AppFilterOarsValue.UNKNOWN: "unknown",
EosParentalControls.AppFilterOarsValue.NONE: "none",
EosParentalControls.AppFilterOarsValue.MILD: "mild",
EosParentalControls.AppFilterOarsValue.MODERATE: "moderate",
EosParentalControls.AppFilterOarsValue.INTENSE: "intense",
}
try:
return mapping[value]
except KeyError:
return "invalid (OARS value {})".format(value)
def command_get(user, quiet=False, interactive=True):
"""Get the app filter for the given user."""
user_id = __lookup_user_id_or_error(user)
@ -121,6 +138,17 @@ def command_check(user, path, quiet=False, interactive=True):
raise SystemExit(EXIT_PATH_NOT_ALLOWED)
def command_oars_section(user, section, quiet=False, interactive=True):
"""Get the value of the given OARS section for the given user, according
to their OARS filter."""
user_id = __lookup_user_id_or_error(user)
app_filter = __get_app_filter_or_error(user_id, interactive)
value = app_filter.get_oars_value(section)
print('OARS section {} for user {} has value {}'.format(
section, user_id, __oars_value_to_string(value)))
def main():
# Parse command line arguments
parser = argparse.ArgumentParser(
@ -164,6 +192,18 @@ def main():
parser_check.add_argument('path',
help='path to a program to check')
# oars-section command
parser_oars_section = subparsers.add_parser('oars-section',
parents=[common_parser],
help='get the value of a '
'given OARS section')
parser_oars_section.set_defaults(function=command_oars_section)
parser_oars_section.add_argument('user', default='', nargs='?',
help='user ID or username to get the '
'OARS filter for (default: current '
'user)')
parser_oars_section.add_argument('section', help='OARS section to get')
# Parse the command line arguments and run the subcommand.
args = parser.parse_args()
args_dict = dict((k, v) for k, v in vars(args).items() if k != 'function')