]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/python/oils/srfsh.py
TPac: minor i18n string repairs
[working/Evergreen.git] / Open-ILS / src / python / oils / srfsh.py
1 # -----------------------------------------------------------------------
2 # Copyright (C) 2010 Equinox Software, Inc.
3 # Bill Erickson <berick@esilibrary.com>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 # -----------------------------------------------------------------------
15 import oils.utils.idl
16 from oils.utils.utils import md5sum
17 import osrf.json
18
19 def handle_login(srfsh, args):
20     ''' Login w/ args '''
21
22     username = args[0]
23     password = args[1]
24
25     seed = srfsh.handle_request([
26         'open-ils.auth', 
27         'open-ils.auth.authenticate.init', 
28         '"%s"' % username
29     ])
30
31     password = md5sum(seed + md5sum(password))
32
33     response = srfsh.handle_request([
34         'open-ils.auth', 
35         'open-ils.auth.authenticate.complete', 
36
37         osrf.json.to_json( 
38             {   # handle_request accepts json-encoded params
39                 'username'    : username,
40                 'password'    : password,
41                 'type'        : args[2] if len(args) > 2 else None,
42                 'workstation' : args[3] if len(args) > 3 else None
43             }
44         )
45     ])
46
47 def handle_org_setting(srfsh, args):
48     ''' Retrieves the requested org setting.
49
50     Arguments:
51         org unit id,
52         org setting name
53     '''
54
55     org_unit = args[0]
56     setting = args[1]
57
58     srfsh.handle_request([
59         'open-ils.actor', 
60         'open-ils.actor.ou_setting.ancestor_default', 
61         org_unit, 
62         ',"%s"' % setting
63     ])
64
65 def handle_idl(srfsh, args):
66     ''' Handles the 'idl' command.
67
68     Argument options inlude:
69         idl show class <classname>
70     '''
71
72     # all IDL commands require the IDL to be present
73     if oils.utils.idl.IDLParser._global_parser is None:
74         srfsh.report("Loading and parsing IDL...", True, True)
75         oils.utils.idl.IDLParser.parse()
76         srfsh.report("OK\n", True, True)
77
78     if args[0] == 'show':
79
80         if args[1] == 'class':
81             class_ = args[2]
82             srfsh.report(str(oils.utils.idl.IDLParser.get_class(class_)))
83
84
85 def load(srfsh, config): 
86     ''' Srfsh plugin loader '''
87
88     # load the IDL
89     if config.get("load_idl", "") == "true":
90         oils.utils.idl.IDLParser.parse()
91
92     # register custom commands
93     srfsh.add_command(command = 'login', handler = handle_login)
94     srfsh.add_command(command = 'idl', handler = handle_idl)
95     srfsh.add_command(command = 'org_setting', handler = handle_org_setting)
96
97     # add some service names to the tab complete word bank
98     srfsh.tab_complete_words.append('open-ils.auth')
99     srfsh.tab_complete_words.append('open-ils.cstore')
100     # TODO: load services for tab-complete from opensrf settings...
101