[open-ils-commits] r1276 - conifer/branches/rel_1_6_1/tools/python-sample (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 22 16:33:10 EDT 2011


Author: dbs
Date: 2011-03-22 16:33:04 -0400 (Tue, 22 Mar 2011)
New Revision: 1276

Modified:
   conifer/branches/rel_1_6_1/tools/python-sample/osrf_gateway_request.py
Log:
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.


Modified: conifer/branches/rel_1_6_1/tools/python-sample/osrf_gateway_request.py
===================================================================
--- conifer/branches/rel_1_6_1/tools/python-sample/osrf_gateway_request.py	2011-03-22 20:05:28 UTC (rev 1275)
+++ conifer/branches/rel_1_6_1/tools/python-sample/osrf_gateway_request.py	2011-03-22 20:33:04 UTC (rev 1276)
@@ -10,6 +10,7 @@
 import oils.utils.utils
 import osrf.gateway
 import osrf.json
+import sys
 import tempfile
 import urllib2
 
@@ -55,8 +56,6 @@
 
     __authtoken = None
 
-    print("attempting login with user " + username)
-
     seed = request(
         'open-ils.auth', 
         'open-ils.auth.authenticate.init', username).send()
@@ -66,8 +65,8 @@
 
     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 @@
     # 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()
+    print("\tCopy ID: %s" % barcode_copy.id())
+    print("\tCall number ID: %s" % 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 one of the fleshed fields
+    print("\tCopy location: %s\n" % barcode_copy.location().name())
 
-    # Get a plain acn (callnumber) object by ID
+    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())
 
-    # Change the call number and update it
+    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)
+
+    print("Change the call number and update it:")
     call_num.label('FOOTWICH')
     call_num.ischanged(True)
 



More information about the open-ils-commits mailing list