From bba7448a76f69d7a4c090b409eecf1c3575a0b63 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 20 Dec 2010 02:48:32 +0000 Subject: [PATCH] initial openils python srfsh plugin; adds suport for 'login' (which behaves the same as srfsh.c), 'org_setting', and 'idl show class' commands, though the latter 2 are largely proofs of concept and are likely to evolve. TODO: srfsh -> support command help docs during command insert git-svn-id: svn://svn.open-ils.org/ILS/trunk@19022 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/srfsh.py | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Open-ILS/src/python/oils/srfsh.py diff --git a/Open-ILS/src/python/oils/srfsh.py b/Open-ILS/src/python/oils/srfsh.py new file mode 100644 index 000000000..e5baa26f4 --- /dev/null +++ b/Open-ILS/src/python/oils/srfsh.py @@ -0,0 +1,101 @@ +# ----------------------------------------------------------------------- +# Copyright (C) 2010 Equinox Software, Inc. +# Bill Erickson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# ----------------------------------------------------------------------- +import oils.utils.idl +from oils.utils.utils import md5sum +import osrf.json + +def handle_login(srfsh, args): + ''' Login w/ args ''' + + username = args[0] + password = args[1] + + seed = srfsh.handle_request([ + 'open-ils.auth', + 'open-ils.auth.authenticate.init', + '"%s"' % username + ]) + + password = md5sum(seed + md5sum(password)) + + response = srfsh.handle_request([ + 'open-ils.auth', + 'open-ils.auth.authenticate.complete', + + osrf.json.to_json( + { # handle_request accepts json-encoded params + 'username' : username, + 'password' : password, + 'type' : args[2] if len(args) > 2 else None, + 'workstation' : args[3] if len(args) > 3 else None + } + ) + ]) + +def handle_org_setting(srfsh, args): + ''' Retrieves the requested org setting. + + Arguments: + org unit id, + org setting name + ''' + + org_unit = args[0] + setting = args[1] + + srfsh.handle_request([ + 'open-ils.actor', + 'open-ils.actor.ou_setting.ancestor_default', + org_unit, + ',"%s"' % setting + ]) + +def handle_idl(srfsh, args): + ''' Handles the 'idl' command. + + Argument options inlude: + idl show class + ''' + + # all IDL commands require the IDL to be present + if oils.utils.idl.IDLParser._global_parser is None: + srfsh.report("Loading and parsing IDL...", True, True) + oils.utils.idl.IDLParser.parse() + srfsh.report("OK\n", True, True) + + if args[0] == 'show': + + if args[1] == 'class': + class_ = args[2] + srfsh.report(str(oils.utils.idl.IDLParser.get_class(class_))) + + +def load(srfsh, config): + ''' Srfsh plugin loader ''' + + # load the IDL + if config.get("load_idl", "") == "true": + oils.utils.idl.IDLParser.parse() + + # register custom commands + srfsh.add_command(command = 'login', handler = handle_login) + srfsh.add_command(command = 'idl', handler = handle_idl) + srfsh.add_command(command = 'org_setting', handler = handle_org_setting) + + # add some service names to the tab complete word bank + srfsh.tab_complete_words.append('open-ils.auth') + srfsh.tab_complete_words.append('open-ils.cstore') + # TODO: load services for tab-complete from opensrf settings... + -- 2.11.0