commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5179 - trunk/gnue-appserver/src/classrep


From: reinhard
Subject: r5179 - trunk/gnue-appserver/src/classrep
Date: Fri, 27 Feb 2004 10:28:31 -0600 (CST)

Author: reinhard
Date: 2004-02-27 10:28:29 -0600 (Fri, 27 Feb 2004)
New Revision: 5179

Modified:
   trunk/gnue-appserver/src/classrep/SchemaSupport.py
Log:
Minor code cleanup.


Modified: trunk/gnue-appserver/src/classrep/SchemaSupport.py
===================================================================
--- trunk/gnue-appserver/src/classrep/SchemaSupport.py  2004-02-27 15:58:29 UTC 
(rev 5178)
+++ trunk/gnue-appserver/src/classrep/SchemaSupport.py  2004-02-27 16:28:29 UTC 
(rev 5179)
@@ -4,19 +4,19 @@
 #
 # This file is part of GNU Enterprise.
 #
-# GNU Enterprise 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 
+# GNU Enterprise 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, or (at your option) any later version.
 #
-# GNU Enterprise 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 
+# GNU Enterprise 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.
 #
-# You should have received a copy of the GNU General Public 
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
 # $Id$
@@ -84,20 +84,20 @@
 
     # If no specific items are requested, we will use classes
     if items is None or len (items) == 0:
-      classList = self.__classes.keys ()
+      classdefs = self.__classes.keys ()
 
     # otherwise check all items and create the classlist
     else:
-      classList = []
+      classdefs = []
 
       for item in items:
         # if item is a module add all it's classes to the list
         if Namespace.getNamespaceId (item) == Namespace.NSID_MODULE:
-          classList.extend (self.__modules [item].classes.keys ())
+          classdefs.extend (self.__modules [item].classes.values ())
 
         # if item is a class add it to the list
         elif Namespace.getNamespaceId (item) == Namespace.NSID_CLASS:
-          classList.append (item)
+          classdefs.append (self.__classes [item])
 
         # otherwise item is of no use to us
         else:
@@ -107,24 +107,24 @@
     schema.title   = _("Appserver Schema Dump")
     schema.author  = _("Appserver SchemaSupport")
     schema.version = _("1.0")
-      
+
     gsTables = GSTables (schema)
 
     # Schema-Definition
     if wtype.lower () in ["both", "schema"]:
-      for classname in classList:
-        self.__createTableDef (gsTables, self.__classes [classname])
+      for classdef in classdefs:
+        self.__createTableDef (gsTables, classdef)
 
     # Data
     if wtype.lower () in ["both", "data"]:
       gsData = GSData (schema)
-      self.__createDataList (gsData, classList)
+      self.__createDataList (gsData, classdefs)
 
     if filename is None:
       dest = sys.stdout
     else:
       dest = open (filename, 'w')
-      
+
     dest.write ('<?xml version="1.0" encoding="UTF-8"?>\n')
     dest.write (_('<!-- Schema definition created by GNUe Appserver\'s ') + \
                 _('Schema Support. -->\n'))
@@ -146,7 +146,7 @@
     fields = GSFields (table)
     GSConstraints (table)
     GSIndexes (table)
-      
+
     for cProp in classdef.properties.values ():
       field = GSField (fields)
       field.name        = unicode (cProp.column, "utf-8")
@@ -167,17 +167,16 @@
 
         pkf = GSPKField (pk)
         pkf.name = 'gnue_id'
-          
-                  
+
+
   # ---------------------------------------------------------------------------
   # Dump all tabledata from a given tablelist
   # ---------------------------------------------------------------------------
-  def __createDataList (self, gsData, classList):
-    # first we need a list of all modules used in classList
+  def __createDataList (self, gsData, classdefs):
+    # first we need a list of all modules used in classdefs
     modules = {}
-    for classname in classList:
-      m = self.__classes[classname].module
-      modules [m.fullName] = m
+    for classdef in classdefs:
+      modules [classdef.module.fullName] = classdef.module
 
     # dump one row from gnue_module for all items in modules
     moddata = GSTableData (gsData)
@@ -198,19 +197,18 @@
     tabledata.name      = 'gnue_class_dump'
     tabledata.tablename = 'gnue_class'
     tablerows = GSRows (tabledata)
-      
-    # and all their properties 
+
+    # and all their properties
     propdata = GSTableData (gsData)
     propdata.name      = 'gnue_property_dump'
     propdata.tablename = 'gnue_property'
     proprows = GSRows (propdata)
 
-    for classname in classList:
-      classdef = self.__classes [classname]
+    for classdef in classdefs:
       cProp = self.__classes ["gnue_class"].properties
-          
+
       # save tabledata
-      row = GSRow (tablerows)              
+      row = GSRow (tablerows)
 
       self.__buildValue (row, cProp ["gnue_id"], classdef.gnue_id)
       self.__buildValue (row, cProp ["gnue_module"], classdef.gnue_module)
@@ -239,10 +237,10 @@
     value = GSValue (row)
     value.field = prop.column
     value.type  = prop.dbFullType
-    GContent (value, 
+    GContent (value,
       unicode (self.__nativeToString (data, prop.dbFullType), 'utf-8'))
 
-  
+
   # ---------------------------------------------------------------------------
   # Convert a native python object to a string according to datatype
   # ---------------------------------------------------------------------------
@@ -267,8 +265,8 @@
 
       else:
         return str (native)
-    
 
+
     elif datatype [:6] == "number":
       if native is None:
         return "0"
@@ -328,7 +326,7 @@
     elif datatype == "datetime":
       if isinstance (native, mx.DateTime.DateTimeType):
         return str (native)
-    
+
       else:
         raise EInvalidValue (native, _("is not a valid datetime object"))
 
@@ -342,10 +340,10 @@
 
 if __name__ == '__main__':
   from gnue.appserver.test import testApp
-  
+
   app = testApp()
   sm = app.getSessionManager ()
-  
+
   gsdSupp = SchemaSupport (sm.modules, sm.classes)
 
   gsdSupp.writeSchemaToFile ('AS_Schema.gsd')





reply via email to

[Prev in Thread] Current Thread [Next in Thread]