[open-ils-commits] r959 - constrictor/trunk/contrib/sip2 (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Aug 14 10:40:57 EDT 2010
Author: erickson
Date: 2010-08-14 10:40:54 -0400 (Sat, 14 Aug 2010)
New Revision: 959
Added:
constrictor/trunk/contrib/sip2/sip2_mixed_batch.py
constrictor/trunk/contrib/sip2/sip2_patron_info_endurance.py
Modified:
constrictor/trunk/contrib/sip2/sip2_client.py
Log:
created generic sip request task class to reduce code footprint; added patron info request task w/ script; added mixed batch script
Modified: constrictor/trunk/contrib/sip2/sip2_client.py
===================================================================
--- constrictor/trunk/contrib/sip2/sip2_client.py 2010-08-12 05:35:01 UTC (rev 958)
+++ constrictor/trunk/contrib/sip2/sip2_client.py 2010-08-14 14:40:54 UTC (rev 959)
@@ -18,9 +18,27 @@
import constrictor.script
import constrictor.log as log
-line_terminator = '\r\n'
+line_terminator = '\r'
class SIP2Client(object):
+
+ # generic request class
+ class SIP2RequestTask(constrictor.task.Task):
+
+ def __init__(self, client, msg):
+ constrictor.task.Task.__init__(self, self.__class__.__name__)
+ self.client = client
+ self.msg = msg
+
+ def run(self, **kw):
+ log.log_info("%s" % self.name)
+ self.client.send_msg(self.msg)
+ data = self.client.recv_msg()
+ if data is None:
+ return False
+ log.log_info('SIP2 %s response: %s' % (self.name, data))
+ return data
+
def __init__(self, server, port):
self.server = server
@@ -74,7 +92,7 @@
return None
if buf is None or buf == '': # server kicked us off
- log.log_error("SIP2 server ejected us")
+ log.log_error("SIP2 server rejected us!")
return None
data = data + buf
@@ -128,47 +146,34 @@
def item_info_request(self, institution, copy_barcode):
client = self
+ msg = '1720060110 215612AO%s|AB%s|' % (institution, copy_barcode)
- class ItemInfoTask(constrictor.task.Task):
-
- def __init__(self, name=None):
- constrictor.task.Task.__init__(self, self.__class__.__name__)
-
- def run(self, **kw):
- log.log_info("ItemInfoTask: %s" % copy_barcode)
- msg = '1720060110 215612AO%s|AB%s|' % (institution, copy_barcode)
- client.send_msg(msg)
- data = client.recv_msg()
- if data is None:
- return False
- log.log_info('SIP2 item info response: %s' % data)
- return data
+ class ItemInfoTask(SIP2Client.SIP2RequestTask):
+ def __init__(self):
+ SIP2Client.SIP2RequestTask.__init__(self, client, msg)
return ItemInfoTask().start()
def patron_status_request(self, institution, user_barcode, user_password):
client = self
+ msg = '2300120060101 084237AO%s|AA%s|AD%s|AC|' % (institution, user_barcode, user_password)
- class PatronStatusTask(constrictor.task.Task):
+ class PatronStatusTask(SIP2Client.SIP2RequestTask):
+ def __init__(self):
+ SIP2Client.SIP2RequestTask.__init__(self, client, msg)
- def __init__(self, name=None):
- constrictor.task.Task.__init__(self, self.__class__.__name__)
+ return PatronStatusTask().start()
- def run(self, **kw):
- log.log_info("PatronStatusTask: %s" % user_barcode)
- msg = '2300120060101 084237AO%s|AA%s|AD%s|AC|' % (institution, user_barcode, user_password)
- client.send_msg(msg)
- data = client.recv_msg()
- if data is None:
- return False
- log.log_info('SIP2 patron status response: %s' % data)
- return data
- return PatronStatusTask().start()
+ def patron_info_request(self, institution, user_barcode):
+ client = self
+ msg = '6300020060329 201700 AO%s|AA%s|' %(institution, user_barcode)
-
+ class PatronInfoTask(SIP2Client.SIP2RequestTask):
+ def __init__(self):
+ SIP2Client.SIP2RequestTask.__init__(self, client, msg)
+ return PatronInfoTask().start()
-
Added: constrictor/trunk/contrib/sip2/sip2_mixed_batch.py
===================================================================
--- constrictor/trunk/contrib/sip2/sip2_mixed_batch.py (rev 0)
+++ constrictor/trunk/contrib/sip2/sip2_mixed_batch.py 2010-08-14 14:40:54 UTC (rev 959)
@@ -0,0 +1,62 @@
+# -----------------------------------------------------------------------
+# 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 SIP2MixedBatchScript(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()]
+
+ user_barcodes = props.get_property('sip2.userBarcodes').split(',')
+ user_passwords = props.get_property('sip2.userPasswords').split(',')
+
+ user_barcode = user_barcodes[constrictor.script.ScriptThread.get_thread_id()]
+ user_password = user_passwords[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
+ if not client.patron_status_request(institution, user_barcode, user_password):
+ break
+ if not client.patron_info_request(institution, user_barcode):
+ break
+
+ client.disconnect()
+
+constrictor.script.ScriptManager.go(SIP2MixedBatchScript())
+
+
Added: constrictor/trunk/contrib/sip2/sip2_patron_info_endurance.py
===================================================================
--- constrictor/trunk/contrib/sip2/sip2_patron_info_endurance.py (rev 0)
+++ constrictor/trunk/contrib/sip2/sip2_patron_info_endurance.py 2010-08-14 14:40:54 UTC (rev 959)
@@ -0,0 +1,50 @@
+# -----------------------------------------------------------------------
+# 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 SIP2PatronInfoEnduranceScript(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'))
+
+ user_barcodes = props.get_property('sip2.userBarcodes').split(',')
+ user_barcode = user_barcodes[constrictor.script.ScriptThread.get_thread_id()]
+
+ client = sip2_client.SIP2Client(server, port)
+
+ if client.init_socket() and client.login(username, password, institution):
+ for i in range(100):
+ if not client.patron_info_request(institution, user_barcode):
+ break
+
+ client.disconnect()
+
+constrictor.script.ScriptManager.go(SIP2PatronInfoEnduranceScript())
+
+
More information about the open-ils-commits
mailing list