[open-ils-commits] r19021 - trunk/Open-ILS/src/python/oils/utils (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Dec 19 21:38:46 EST 2010


Author: erickson
Date: 2010-12-19 21:38:45 -0500 (Sun, 19 Dec 2010)
New Revision: 19021

Modified:
   trunk/Open-ILS/src/python/oils/utils/idl.py
Log:
added a simple stringifierr for IDLClass and IDLField; capture 'class' in links

Modified: trunk/Open-ILS/src/python/oils/utils/idl.py
===================================================================
--- trunk/Open-ILS/src/python/oils/utils/idl.py	2010-12-20 02:25:16 UTC (rev 19020)
+++ trunk/Open-ILS/src/python/oils/utils/idl.py	2010-12-20 02:38:45 UTC (rev 19021)
@@ -123,9 +123,10 @@
         for link in [l for l in links.childNodes if l.nodeName == 'link']:
             obj = IDLLink(
                 field = idlobj.get_field(self._get_attr(link, 'field')),
-                rel_type = self._get_attr(link, 'rel_type'),
+                reltype = self._get_attr(link, 'reltype'),
                 key = self._get_attr(link, 'key'),
-                map = self._get_attr(link, 'map')
+                map = self._get_attr(link, 'map'),
+                class_ = self._get_attr(link, 'class')
             )
             idlobj.links.append(obj)
 
@@ -156,6 +157,7 @@
             )
 
             idlobj.fields.append(obj)
+            idlobj.field_map[obj.name] = obj
             position += 1
 
         for name in ['isnew', 'ischanged', 'isdeleted']: 
@@ -183,15 +185,31 @@
         self.sequence = kwargs.get('sequence')
         self.fields = []
         self.links = []
+        self.field_map = {}
 
         if self.virtual and self.virtual.lower() == 'true':
             self.virtual = True
         else:
             self.virtual = False
 
+    def __str__(self):
+        ''' Stringify the parsed IDL ''' # TODO: improve the format/content
+
+        s = '-'*60 + '\n'
+        s += "%s [%s] %s\n" % (self.label, self.name, self.tablename)
+        s += '-'*60 + '\n'
+        idx = 0
+        for f in self.fields:
+            s += "[%d] " % idx
+            if idx < 10: s += " "
+            s += str(f) + '\n'
+            idx += 1
+
+        return s
+
     def get_field(self, field_name):
         try:
-            return [f for f in self.fields if f.name == field_name][0]
+            return self.field_map[field_name]
         except:
             msg = "No field '%s' in IDL class '%s'" % (field_name, self.name)
             osrf.log.log_warn(msg)
@@ -216,15 +234,26 @@
         else:
             self.virtual = False
 
+    def __str__(self):
+        ''' Format as field name and data type, plus linked class for links. '''
+        s = self.name
+        if self.rpt_datatype:
+            s += " [" + self.rpt_datatype
+            if self.rpt_datatype == 'link':
+                link = [ l for l in self.idl_class.links if l.field.name == self.name ]
+                if len(link) > 0 and link[0].class_:
+                    s += " @%s" % link[0].class_
+            s += ']'
+        return s
 
+
 class IDLLink(object):
     def __init__(self, field, **kwargs):
         '''
             @param field The IDLField object this link references
         '''
         self.field = field
-        self.rel_type = kwargs.get('rel_type')
+        self.reltype = kwargs.get('reltype')
         self.key = kwargs.get('key')
         self.map = kwargs.get('map')
-
-
+        self.class_ = kwargs.get('class_')



More information about the open-ils-commits mailing list