[open-ils-commits] r8398 - in trunk/Open-ILS/src/python/oils: . utils

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jan 17 12:37:33 EST 2008


Author: erickson
Date: 2008-01-17 12:11:51 -0500 (Thu, 17 Jan 2008)
New Revision: 8398

Added:
   trunk/Open-ILS/src/python/oils/event.py
Modified:
   trunk/Open-ILS/src/python/oils/utils/utils.py
Log:
added a generic event class to model ILS events, removed functional event code from the util class

Added: trunk/Open-ILS/src/python/oils/event.py
===================================================================
--- trunk/Open-ILS/src/python/oils/event.py	                        (rev 0)
+++ trunk/Open-ILS/src/python/oils/event.py	2008-01-17 17:11:51 UTC (rev 8398)
@@ -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

Modified: trunk/Open-ILS/src/python/oils/utils/utils.py
===================================================================
--- trunk/Open-ILS/src/python/oils/utils/utils.py	2008-01-17 16:51:35 UTC (rev 8397)
+++ trunk/Open-ILS/src/python/oils/utils/utils.py	2008-01-17 17:11:51 UTC (rev 8398)
@@ -23,20 +23,6 @@
 # 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)



More information about the open-ils-commits mailing list