From a006debc0f853aaa35aafe6815dcc8ee230e8177 Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 22 Mar 2011 20:33:04 +0000 Subject: [PATCH] We can access fleshed fields if we use the field name, not the class hint D'oh! Bill pointed this brain damage out to me, too. Also, clean up the output somewhat and move the authentication near to the end so that at least some of the methods can be invoked. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1276 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- tools/python-sample/osrf_gateway_request.py | 63 ++++++++++++++--------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/tools/python-sample/osrf_gateway_request.py b/tools/python-sample/osrf_gateway_request.py index 257263f0db..ef20d1a82a 100644 --- a/tools/python-sample/osrf_gateway_request.py +++ b/tools/python-sample/osrf_gateway_request.py @@ -10,6 +10,7 @@ import oils.utils.idl import oils.utils.utils import osrf.gateway import osrf.json +import sys import tempfile import urllib2 @@ -55,8 +56,6 @@ def login(username, password, workstation=None): __authtoken = None - print("attempting login with user " + username) - seed = request( 'open-ils.auth', 'open-ils.auth.authenticate.init', username).send() @@ -66,8 +65,8 @@ def login(username, password, workstation=None): result = request( 'open-ils.auth', - 'open-ils.auth.authenticate.complete', - { 'workstation' : workstation, + 'open-ils.auth.authenticate.complete', { + 'workstation' : workstation, 'username' : username, 'password' : password, 'type' : 'staff' @@ -120,50 +119,50 @@ if __name__ == '__main__': # Pull all of our object definitions together load_idl() - # Log in and get an authtoken - authtoken = login('foo', 'bar') - - # Issue a plain old position-dependent request + print("Issue a plain old position-dependent request:") req = request('open-ils.search', 'open-ils.search.biblio.record.copy_count', 105, 891001, None) res = req.send() - print(res[0]) + print("\t%s\n" % res[0]) - # Get a plain Jane acp (copy) object by barcode + print("Get a plain Jane acp (copy) object by barcode:") barcode = '791068-1001' req = request('open-ils.search', 'open-ils.search.asset.copy.find_by_barcode', barcode) barcode_copy = req.send() - print "Raw JSON: ", osrf.json.to_json(barcode_copy) + print("\tRaw JSON: %s" % osrf.json.to_json(barcode_copy)) # id() and call_number() are fields defined in fm_IDL.xml - print "Copy ID: ", barcode_copy.id() - print "Call number ID: ", barcode_copy.call_number() + print("\tCopy ID: %s" % barcode_copy.id()) + print("\tCall number ID: %s\n" % barcode_copy.call_number()) - # Get a fleshed out copy (now with more fields!) by barcode + print("Get a fleshed out copy (now with more fields!) by barcode:") req = request('open-ils.search', 'open-ils.search.asset.copy.fleshed2.find_by_barcode', barcode) barcode_copy = req.send() - print "Raw JSON: ", osrf.json.to_json(barcode_copy) + print("\tRaw JSON: %s" % osrf.json.to_json(barcode_copy)) # id() and call_number() are fields defined in fm_IDL.xml - print "Copy ID: ", barcode_copy.id() - print "Call number ID: ", barcode_copy.call_number() - - # Note - fleshed fields don't appear to be retrievable with the expected syntax - # The following does _not_ work: - # - # print "Copy location: ", barcode_copy.acpl().name() - # - # And the following just prints null values for an acpl object: - # - # print osrf.json.to_json(barcode_copy.acpl()) - - # Get a plain acn (callnumber) object by ID + print("\tCopy ID: %s" % barcode_copy.id()) + print("\tCall number ID: %s" % barcode_copy.call_number()) + + # Get one of the fleshed fields + print("\tCopy location: %s\n" % barcode_copy.location().name()) + + print("Get a plain acn (callnumber) object by ID:") req = request('open-ils.search', 'open-ils.search.asset.call_number.retrieve', barcode_copy.call_number()) call_num = req.send() - print "Raw JSON: ", osrf.json.to_json(call_num) - print "Call number ID: ", call_num.id() - print "Call number label: ", call_num.label() + print("\tRaw JSON: %s" % osrf.json.to_json(call_num)) + print("\tCall number ID: %s" % call_num.id()) + print("\tCall number label: %s\n" % call_num.label()) + + authtoken = '' + + try: + # Log in and get an authtoken + authtoken = login('foo', 'bar') + except AuthException, exc: + print("Failed logging in: %s" % str(exc)) + sys.exit(1) - # Change the call number and update it + print("Change the call number and update it:") call_num.label('FOOTWICH') call_num.ischanged(True) -- 2.11.0