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
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
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):
-
- def __init__(self, name=None):
- constrictor.task.Task.__init__(self, self.__class__.__name__)
-
- 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
+ class PatronStatusTask(SIP2Client.SIP2RequestTask):
+ def __init__(self):
+ SIP2Client.SIP2RequestTask.__init__(self, client, msg)
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()
--- /dev/null
+# -----------------------------------------------------------------------
+# Copyright (C) 2010 Equinox Software, Inc
+# Bill Erickson <erickson@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())
+
+
--- /dev/null
+# -----------------------------------------------------------------------
+# Copyright (C) 2010 Equinox Software, Inc
+# Bill Erickson <erickson@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())
+
+