Attached is a Python curses script for checking an item out to a patron.
I'm not really sure what the purpose is, but I saw a Python curses tutorial
at [1] and thought I'd have some fun with it ;)

On an Evergreen server,  run the script as the 'opensrf' user.  It uses
/home/opensrf/.srfsh.xml as the configuration file.  It should work on
Evergreen 1.4+, but it's only tested on trunk.

Anyway, it was fun and if someone wants to turn it into something useful,
even better.

-b

[1] http://www.tuxradar.com/content/code-project-build-ncurses-ui-python

-- 
Bill Erickson
| VP, Software Development & Integration
| Equinox Software, Inc. / The Evergreen Experts
| phone: 877-OPEN-ILS (673-6457)
| email: erick...@esilibrary.com
| web: http://esilibrary.com
#!/usr/bin/python
# -----------------------------------------------------------------------
# Copyright (C) 2009 Equinox Software, Inc
# Bill Erickson <erick...@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 2
# 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
from os import system
import curses
import osrf.ses, osrf.log
import oils.system, oils.utils.utils, oils.event

session = None
screen = None

class ILSSession(object):
    def __init__(self):
        self.username = None
        self.authtoken = None


def get_param(prompt_string):
    screen.clear()
    screen.border(0)
    screen.addstr(2, 2, prompt_string)
    screen.refresh()
    input = screen.getstr(6, 6, 60)
    return input


def do_login():
    username = get_param("Enter your username")
    password = get_param("Enter your password")
    auth = oils.utils.utils.login(username, password)
    session.username = username
    oils.event.Event.parse_and_raise(auth) 
    session.authtoken = auth['payload']['authtoken']

def do_checkout():

    patron_barcode = get_param("Enter the patron's barcode")
    copy_barcode = get_param("Enter the copy barcode")

     # print user summary info to screen
#    user = osrf.ses.ClientSession.atomic_request(
#        'open-ils.actor', 
#        'open-ils.actor.user.fleshed.retrieve_by_barcode',
#        session.authtoken, patron_barcode
#    )
#    oils.event.Event.parse_and_raise(user);


    checkout = osrf.ses.ClientSession.atomic_request(
        'open-ils.circ', 
        'open-ils.circ.checkout.full',
        session.authtoken,
        {'copy_barcode' : copy_barcode, 'patron_barcode' : patron_barcode}
    )

    if type(checkout) != list:
        checkout = [checkout]

    screen.clear()
    screen.border(0)
    scr_index = 2
    success = True

    for event in checkout:
        event = oils.event.Event.parse_event(event)
        screen.addstr(scr_index, 2, "Checkout event: %s" % event.text_code)
        scr_index += 1
        if event.text_code != 'SUCCESS':
            success = False

    scr_index += 1
    if success:
        screen.addstr(scr_index, 2, "Checkout Succeeded!")
    else:
        screen.addstr(scr_index, 2, "Checkout Failed")

    screen.refresh()

    scr_index += 2
    msg = "Enter to continue..."
    screen.addstr(scr_index, 2, msg)
    screen.getstr(scr_index, len(msg) + 2, 0)


def main_loop():
    global screen
    global session

    session = ILSSession()

    screen = curses.initscr()
    screen.clear()
    screen.border(0)
    screen.addstr(2, 2, "Connecting...")
    screen.refresh()

    oils.system.System.connect(
        config_file = '/home/opensrf/.srfsh.xml',
        config_context = 'srfsh'
    )

    while session.authtoken is None:
        do_login()

    x = 0

    while x != ord('9'):

        screen.clear()
        screen.border(0)
        screen.addstr(2, 2, "Please choose an action...")
        screen.addstr(4, 4, "1 - Checkout Item")
        screen.addstr(5, 4, "9 - Exit")
        screen.refresh()

        x = screen.getch()
        osrf.log.log_info("User chose option %s" % str(x))

        if x == ord('1'):
            do_checkout()

    curses.endwin()

    # logout and disconnect...



# ------------------------------------------------------

main_loop()

Reply via email to