From e820e647e6a39c4e56af5faeda93f11576d6e256 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 17 Jan 2008 17:11:51 +0000 Subject: [PATCH] added a generic event class to model ILS events, removed functional event code from the util class git-svn-id: svn://svn.open-ils.org/ILS/trunk@8398 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/event.py | 32 ++++++++++++++++++++++++++++++++ Open-ILS/src/python/oils/utils/utils.py | 14 -------------- 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 Open-ILS/src/python/oils/event.py diff --git a/Open-ILS/src/python/oils/event.py b/Open-ILS/src/python/oils/event.py new file mode 100644 index 0000000000..e8f2481650 --- /dev/null +++ b/Open-ILS/src/python/oils/event.py @@ -0,0 +1,32 @@ + +class Event(object): + ''' Generic ILS event object ''' + + def __init__(self, evt_hash={}): + self.code = evt_hash.get('ilsevent') or -1 + self.text_code = evt_hash.get('textcode') or '' + self.desc = evt_hash.get('desc') or '' + self.payload = evt_hash.get('payload') or None + self.debug = evt_hash.get('stacktrace') or '' + self.servertime = evt_hash.get('servertime') or '' + + self.success = False + if self.code == int(0): + self.success = True + + def __str__(self): + return '%s: %s:%s -> %s' % ( + self.__class__.__name__, self.code, self.text_code, self.desc) + + # XXX eventually, add events file parsing... + + @staticmethod + def parse_event(evt=None): + ''' If the provided evt object is a dictionary object that looks + like an ILS event, construct an Event object and return it. + Returns None otherwise. ''' + + if evt and 'ilsevent' in evt and 'textcode' in evt: + return Event(evt) + + return None diff --git a/Open-ILS/src/python/oils/utils/utils.py b/Open-ILS/src/python/oils/utils/utils.py index 1941a85759..b1fd037481 100644 --- a/Open-ILS/src/python/oils/utils/utils.py +++ b/Open-ILS/src/python/oils/utils/utils.py @@ -23,20 +23,6 @@ from osrf.log import * # Grab-bag of general utility functions # ----------------------------------------------------------------------- -def isEvent(evt): - return (evt and isinstance(evt, dict) and evt.get('ilsevent') != None) - -def eventCode(evt): - if isEvent(evt): - return evt['ilsevent'] - return None - -def eventText(evt): - if isEvent(evt): - return evt['textcode'] - return None - - def md5sum(str): m = md5.new() m.update(str) -- 2.11.0