[open-ils-commits] r945 - in constrictor/trunk: . contrib contrib/sip2 (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Aug 3 11:50:09 EDT 2010


Author: erickson
Date: 2010-08-03 11:50:06 -0400 (Tue, 03 Aug 2010)
New Revision: 945

Added:
   constrictor/trunk/contrib/sip2/
   constrictor/trunk/contrib/sip2/sip2_client.py
   constrictor/trunk/contrib/sip2/sip2_item_info_endurance.py
Modified:
   constrictor/trunk/constrictor.properties
Log:
new SIP2 client contrib module.  currently supports login and item information requests

Modified: constrictor/trunk/constrictor.properties
===================================================================
--- constrictor/trunk/constrictor.properties	2010-08-03 15:50:05 UTC (rev 944)
+++ constrictor/trunk/constrictor.properties	2010-08-03 15:50:06 UTC (rev 945)
@@ -7,7 +7,7 @@
 #constrictor.script=eg_title_hold.py
 
 # comma separated list of directories where test scripts are found
-constrictor.scriptDirs=samples,contrib/evergreen
+constrictor.scriptDirs=samples,contrib/evergreen,contrib/sip2
 
 # local directory to cache test-specific files
 constrictor.cacheDir=cache
@@ -70,3 +70,17 @@
 #evergreen.patronBarcodes=
 #evergreen.osrfConfig=
 #evergreen.osrfConfigContext=
+
+
+
+# ---- Properties for the SIP2 contrib module --------------
+
+
+sip2.username=sip_username
+sip2.password=sip_password
+sip2.institution=example
+sip2.server=sip.example.org
+sip2.port=6001
+sip2.copyBarcodes=
+
+

Added: constrictor/trunk/contrib/sip2/sip2_client.py
===================================================================
--- constrictor/trunk/contrib/sip2/sip2_client.py	                        (rev 0)
+++ constrictor/trunk/contrib/sip2/sip2_client.py	2010-08-03 15:50:06 UTC (rev 945)
@@ -0,0 +1,109 @@
+# -----------------------------------------------------------------------
+# Copyright (C) 2010 Equinox Software, Inc
+# Bill Erickson <erickson at esilibrary.com>
+# 
+# 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 3
+# 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 sys, socket
+import constrictor.task
+import constrictor.script
+import constrictor.log as log
+
+line_terminator = '\r\n'
+
+class SIP2Client(object):
+    
+    def __init__(self, server, port):
+        self.server = server
+        self.port = port
+        self.sock = None
+
+    def init_socket(self):
+
+        try:
+            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        except socket.error, msg:
+            log.log_error("%s\n" % msg[1])
+            return False
+
+        try:
+            self.sock.connect((self.server, self.port))
+        except socket.error, msg:
+            log.log_error("%s\n" % msg[1])
+            return False
+
+        return True
+
+    def send_msg(self, msg):
+        log.log_debug('SIP2 socket sending: %s' % msg)
+        self.sock.send(msg + line_terminator)
+
+    def recv_msg(self):
+        data = ''
+        buf = ''
+
+        while True:
+            buf = self.sock.recv(2048)
+            data = data + buf
+            log.log_debug("SIP2 socket read: %s" % buf)
+            if data[-(len(line_terminator)):] == line_terminator:
+                break
+
+        return data
+
+    def login(self, username, password, institution):
+        client = self
+
+        class LoginTask(constrictor.task.Task):
+
+            def __init__(self):
+                constrictor.task.Task.__init__(self, self.__class__.__name__)
+
+            def run(self, **kw):
+
+                log.log_info("LoginTask: %s %s %s" % (username, password, institution))
+
+                msg = '9300CN%s|CO%s|CP%s|' % (username, password, institution)
+                client.send_msg(msg)
+                data = client.recv_msg()
+
+                if data[:3] == '941':
+                    log.log_info("SIP2 login OK")
+                    return True
+                else:
+                    log.log_error("SIP2 login failed: %s" % data)
+                    return False
+
+        return LoginTask().start()
+
+    def item_info_request(self, institution, copy_barcode):
+
+        client = self
+
+        class ItemInfoTask(constrictor.task.Task):
+
+            def __init__(self, name=None):
+                constrictor.task.Task.__init__(self, self.__class__.__name__)
+
+            def run(self, **kw):
+                # TODO: use a generated date
+                log.log_info("ItemInfoTask: %s" % copy_barcode)
+                msg = '1720060110    215612AO%s|AB%s|' % (institution, copy_barcode)
+                client.send_msg(msg)
+                data = client.recv_msg()
+                # TODO: check for valid response
+                log.log_info('SIP2 item info response: %s' % data)
+                return data
+
+        return ItemInfoTask().start()
+
+

Added: constrictor/trunk/contrib/sip2/sip2_item_info_endurance.py
===================================================================
--- constrictor/trunk/contrib/sip2/sip2_item_info_endurance.py	                        (rev 0)
+++ constrictor/trunk/contrib/sip2/sip2_item_info_endurance.py	2010-08-03 15:50:06 UTC (rev 945)
@@ -0,0 +1,49 @@
+# -----------------------------------------------------------------------
+# Copyright (C) 2010 Equinox Software, Inc
+# Bill Erickson <erickson at esilibrary.com>
+# 
+# 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 3
+# 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 constrictor.script
+import constrictor.properties
+import constrictor.log as log
+import sip2_client
+
+
+class SIP2ItemInfoEnduranceScript(constrictor.script.Script):
+
+    def __init__(self):
+        constrictor.script.Script.__init__(self)
+
+    def run(self):
+        props = constrictor.properties.Properties.get_properties()
+
+        username = props.get_property('sip2.username')
+        password = props.get_property('sip2.password')
+        institution = props.get_property('sip2.institution')
+        server = props.get_property('sip2.server')
+        port = int(props.get_property('sip2.port'))
+
+        barcodes = props.get_property('sip2.copyBarcodes').split(',')
+        copy_barcode = barcodes[constrictor.script.ScriptThread.get_thread_id()]
+
+        client = sip2_client.SIP2Client(server, port)
+        client.init_socket()
+
+        if client.login(username, password, institution):
+            for i in range(100):
+                if not client.item_info_request(institution, copy_barcode):
+                    break
+
+constrictor.script.ScriptManager.go(SIP2ItemInfoEnduranceScript())
+
+



More information about the open-ils-commits mailing list