]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/python/oils/srfsh.py
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[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_auth_verify(srfsh, args):
48     ''' Verify auth w/ args '''
49
50     username = args[0]
51     password = args[1]
52
53     seed = srfsh.handle_request([
54         'open-ils.auth', 
55         'open-ils.auth.authenticate.init', 
56         '"%s"' % username
57     ])
58
59     password = md5sum(seed + md5sum(password))
60
61     response = srfsh.handle_request([
62         'open-ils.auth', 
63         'open-ils.auth.authenticate.verify', 
64
65         osrf.json.to_json( 
66             {   # handle_request accepts json-encoded params
67                 'username'    : username,
68                 'password'    : password,
69                 'type'        : args[2] if len(args) > 2 else None,
70             }
71         )
72     ])
73
74
75 def handle_org_setting(srfsh, args):
76     ''' Retrieves the requested org setting.
77
78     Arguments:
79         org unit id,
80         org setting name
81     '''
82
83     org_unit = args[0]
84     setting = args[1]
85
86     srfsh.handle_request([
87         'open-ils.actor', 
88         'open-ils.actor.ou_setting.ancestor_default', 
89         org_unit, 
90         ',"%s"' % setting
91     ])
92
93 def handle_idl(srfsh, args):
94     ''' Handles the 'idl' command.
95
96     Argument options inlude:
97         idl show class <classname>
98     '''
99
100     # all IDL commands require the IDL to be present
101     if oils.utils.idl.IDLParser._global_parser is None:
102         srfsh.report("Loading and parsing IDL...", True, True)
103         oils.utils.idl.IDLParser.parse()
104         srfsh.report("OK\n", True, True)
105
106     if args[0] == 'show':
107
108         if args[1] == 'class':
109             class_ = args[2]
110             srfsh.report(str(oils.utils.idl.IDLParser.get_class(class_)))
111
112
113 def load(srfsh, config): 
114     ''' Srfsh plugin loader '''
115
116     # load the IDL
117     if config.get("load_idl", "") == "true":
118         oils.utils.idl.IDLParser.parse()
119
120     # register custom commands
121     srfsh.add_command(command = 'login', handler = handle_login)
122     srfsh.add_command(command = 'auth_verify', handler = handle_auth_verify)
123     srfsh.add_command(command = 'idl', handler = handle_idl)
124     srfsh.add_command(command = 'org_setting', handler = handle_org_setting)
125
126     # add some service names to the tab complete word bank
127     srfsh.tab_complete_words.append('open-ils.auth')
128     srfsh.tab_complete_words.append('open-ils.cstore')
129     # TODO: load services for tab-complete from opensrf settings...
130