commit-gnue
[Top][All Lists]
Advanced

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

r5078 - in trunk/gnue-appserver: . scripts src src/classrep


From: johannes
Subject: r5078 - in trunk/gnue-appserver: . scripts src src/classrep
Date: Sun, 8 Feb 2004 03:31:05 -0600 (CST)

Author: johannes
Date: 2004-02-08 03:31:03 -0600 (Sun, 08 Feb 2004)
New Revision: 5078

Added:
   trunk/gnue-appserver/scripts/ggcvs
   trunk/gnue-appserver/scripts/gnue-gsdgen
   trunk/gnue-appserver/src/geasGsdGen.py
Modified:
   trunk/gnue-appserver/setup.cvs
   trunk/gnue-appserver/src/classrep/SchemaSupport.py
   trunk/gnue-appserver/src/test.py
Log:
With geasGsdGen.py (gnue-gsdgen) a user can generate gsd files from the class
repository using the appserver's SchemaSupport.


Added: trunk/gnue-appserver/scripts/ggcvs
===================================================================
--- trunk/gnue-appserver/scripts/ggcvs  2004-02-07 11:46:20 UTC (rev 5077)
+++ trunk/gnue-appserver/scripts/ggcvs  2004-02-08 09:31:03 UTC (rev 5078)
@@ -0,0 +1,10 @@
+#!/bin/sh
+     PYTHONPATH=/home/johannes/prj/gnue/gnue-common/.cvsdevelbase:$PYTHONPATH; 
export PYTHONPATH
+     SCRIPT="appserver/geasGsdGen.py"
+     if [ "$SCRIPT" != "" ]
+     then
+       /usr/bin/python2.1 
/home/johannes/prj/gnue/gnue-common/.cvsdevelbase/gnue/${SCRIPT} "$@"
+     else
+       /usr/bin/python2.1 "$@"
+     fi
+  
\ No newline at end of file


Property changes on: trunk/gnue-appserver/scripts/ggcvs
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/gnue-appserver/scripts/gnue-gsdgen
===================================================================
--- trunk/gnue-appserver/scripts/gnue-gsdgen    2004-02-07 11:46:20 UTC (rev 
5077)
+++ trunk/gnue-appserver/scripts/gnue-gsdgen    2004-02-08 09:31:03 UTC (rev 
5078)
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+#
+# GNU Enterprise Application Server - Main Script
+#
+# Copyright 2001-2003 Free Software Foundation
+#
+# 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
+# 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
+# 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
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+from gnue.appserver.geasGsdGen import geasGsdGen
+
+if __name__ == '__main__':
+  gsdGen = geasGsdGen ()
+  gsdGen.run ()


Property changes on: trunk/gnue-appserver/scripts/gnue-gsdgen
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id

Modified: trunk/gnue-appserver/setup.cvs
===================================================================
--- trunk/gnue-appserver/setup.cvs      2004-02-07 11:46:20 UTC (rev 5077)
+++ trunk/gnue-appserver/setup.cvs      2004-02-08 09:31:03 UTC (rev 5078)
@@ -25,12 +25,14 @@
 # run that file.  This file is not a standalone script.
 # ********************
 #
+# $Id$
 
 # Add our source tree to the gnue.* heirarchy...
 linkModule('src/','appserver')
 
 # Create our shell script..
 createShell ('gacvs','appserver/geasRpcServer.py')
+createShell ('ggcvs', 'appserver/geasGsdGen.py')
 
 # Add our GNUe RPC resource files to the config directory...
 createLink('grpc/appserver.grpc','%s/share/gnue/grpc/appserver.grpc' % 
CONFDIR, overwrite=1)


Property changes on: trunk/gnue-appserver/setup.cvs
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/gnue-appserver/src/classrep/SchemaSupport.py
===================================================================
--- trunk/gnue-appserver/src/classrep/SchemaSupport.py  2004-02-07 11:46:20 UTC 
(rev 5077)
+++ trunk/gnue-appserver/src/classrep/SchemaSupport.py  2004-02-08 09:31:03 UTC 
(rev 5078)
@@ -19,7 +19,7 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place 
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: SchemaSupport.py,v 1.3 2003/10/21 12:26:50 jvetter Exp $
+# $Id$
 
 from gnue.appserver.classrep import Namespace
 
@@ -30,10 +30,9 @@
 # write schema support
 from gnue.common.schema.Objects import *
 from gnue.common.definitions.GParserHelpers import GContent
+import sys
 
-SCHEMA_STORE_BOTH = 0
-SCHEMA_STORE_SCHEMA = 1
-SCHEMA_STORE_DATA = 2
+SCHEMA_STORE = [ 'schema', 'data', 'both' ]
 SCHEMA_TYPES = { 'string'  : 'string', 
                  'number'  : 'number',
                  'boolean' : 'boolean',
@@ -42,188 +41,242 @@
                  'datetime': 'timestamp' }
 
 
+# =============================================================================
+# Exceptions: Base exception class
+# =============================================================================
+class ESchemaSupport (Exception):
+  def __init__ (self, text):
+    self.__msg = text
+    Exception.__init__ (self, text)
+
+  def __repr__ (self):
+    return self.__msg
+
+
+# =============================================================================
+# Exceptions: Invalid export type
+# =============================================================================
+class EInvalidType (ESchemaSupport):
+  def __init__ (self, etype):
+    ESchemaSupport.__init__ (self, _("Invalid export type: '%s'." % etype))
+
+
+
+# =============================================================================
+# SchemaSupport
+# =============================================================================
 class SchemaSupport:
 
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
   def __init__(self, modules, classes):
-    self._modules = modules
-    self._classes = classes
+    self.__modules = modules
+    self.__classes = classes
 
+
   # ---------------------------------------------------------------------------
-  # Load a Schema from a file and store it in the class repository
-  # Parameter: filename:  name of file to load
-  #            overwrite: if true, old class definitions will be removed
-  #            install:   if true, database tables for the class will be 
created
-  # TODO: a) make this code transactional, i.e. first check, if everything can 
-  #          be done without breaks, then execute.
-  #       b) add global class repository locking
+  # Write a Schema to a file. If filename is omitted stdout is used.
   # ---------------------------------------------------------------------------
-  def loadSchemaFromFile (self, filename, overwrite=0, install=0):
-    input = openResource (filename)
-    schema = GSParser.loadFile (input)
+  def writeSchemaToFile (self, filename = None, items = None, wtype = None):
+    if wtype is None:
+      wtype = "both"
 
-    for table in schema.findChildrenOfType ('GSTable', allowAllChildren = 1):
-      print 'adding Table %s' % table.name
+    elif wtype.lower () not in SCHEMA_STORE:
+      raise EInvalidType (wtype.lower ())
 
-      for field in table.findChildrenOfType ('GSField', allowAllChildren = 1):
-        print '   with field %s:' % field.name
+    # If no specific items are requested, we will use classes
+    if items is None or len (items) == 0:
+      tableList = self.__classes.keys ()
 
-    if overwrite:
-      raise 'Overwrite support not working yet.'
-      
-    if install:
-      # TODO: this job should be done in a quite general way,
-      #       to let the code be reused in reaction on  manual class
-      #       repository changes.
-      raise 'Creation of Schema tables is not supported yet'
+    # otherwise check all items and create the tablelist
+    else:
+      tableList = []
 
-  # ---------------------------------------------------------------------------
-  # Write a Schema to a file
-  # Parameter: filename:  name of file to write to
-  #            classlist: list of classes to write to
-  # TODO: a) add global class repository locking
-  #       b) add a (include system tables) parameter
-  # ---------------------------------------------------------------------------
-  def writeSchemaToFile (self, filename, classlist = None,
-                         type = SCHEMA_STORE_BOTH):
+      for item in items:
+        # if item is a module add all it's classes to the list
+        if Namespace.getNamespaceId (item) == Namespace.NSID_MODULE:
+          tableList.extend (self.__modules [item].classes.keys ())
+
+        # if item is a class add it to the list
+        elif Namespace.getNamespaceId (item) == Namespace.NSID_CLASS:
+          tableList.append (item)
+
+        # otherwise item is of no use to us
+        else:
+          raise Namespace.EInvalidName (item)
+
+
     schema = GSSchema()
-    schema.title   = 'Appserver Schema Dump'
-    schema.author  = 'Appserver SchemaSupport'
-    schema.version = '1.0'
-    # schema.description=''
+    schema.title   = _("Appserver Schema Dump")
+    schema.author  = _("Appserver SchemaSupport")
+    schema.version = _("1.0")
       
-    gstables = GSTables (schema)
+    gsTables = GSTables (schema)
 
-    # use either the given classlist or a list of all classes available
-    tablelist = classlist or self._classes.keys ()
+    # Schema-Definition
+    if wtype.lower () in ["both", "schema"]:
+      for table in tableList:
+        self.__createTableDef (gsTables, table)
 
-    # create the schema definition
-    if (type == SCHEMA_STORE_BOTH) or (type == SCHEMA_STORE_SCHEMA):
-      for tablename in tablelist:
-        self.createTableDef (gstables, tablename)
+    # Data
+    if wtype.lower () in ["both", "data"]:
+      gsData = GSData (schema)
+      self.__createDataList (gsData, tableList)
 
-    # optionally create the datalist
-    if (type == SCHEMA_STORE_BOTH) or (type == SCHEMA_STORE_DATA):
-      gsdata = GSData (schema)
-      self.createDataList (gsdata, tablelist)
-                
-    # create the .gsd-file
-    dest = open (filename, 'w')
+    if filename is None:
+      dest = sys.stdout
+    else:
+      dest = open (filename, 'w')
       
-    dest.write ("""<?xml version="1.0"?>\n""" + 
-      """<!-- Schema definition created by GNUe Appserver's Schema 
Support\n"""+
-      """Dropped Schema includes %s  -->\n""" % tablelist)
-
+    dest.write ('<?xml version="1.0"?>\n')
+    dest.write (_('<!-- Schema definition created by GNUe Appserver\'s ') + \
+                _('Schema Support. -->\n'))
     dest.write (schema.dumpXML ())
     dest.close ()
 
+
   # ---------------------------------------------------------------------------
   # Create the tabledefinition for tablename
   # ---------------------------------------------------------------------------
-  def createTableDef (self, gstables, tablename):
-    table = GSTable (gstables)
+  def __createTableDef (self, gsTables, tablename):
+    table      = GSTable (gsTables)
     table.name = tablename
-    #table.description = ''
       
     # add fields listing (required)
     fields = GSFields (table)
     GSConstraints (table)
     GSIndexes (table)
       
-    for property in self._classes [tablename].properties.values ():
-      # add one field per property
+    aClass = self.__classes [tablename]
+    for cProp in aClass.properties.values ():
       field = GSField (fields)
-      field.name        = property.fullName
-      field.description = property.gnue_comment
+      field.name        = cProp.fullName
+      field.description = cProp.gnue_comment
 
-      # use valid types as is
-      if property.gnue_type in SCHEMA_TYPES.keys ():
-        field.type        = SCHEMA_TYPES [property.gnue_type]
-        field.length      = int (property.gnue_length)
-        field.precision   = int (property.gnue_scale)
+      # map known types 
+      if SCHEMA_TYPES.has_key (cProp.gnue_type):
+        field.type        = SCHEMA_TYPES [cProp.gnue_type]
+        field.length      = int (cProp.gnue_length)
+        field.precision   = int (cProp.gnue_scale)
+
       # everything else should be a reference
       else:
         field.type        = 'string'
         field.length      = 32
         field.precision   = 0
 
-      # TODO: where should 'gnue_module' be stored?
-
-      # set gnue_id to be a primary key
-      if (property.fullName == 'gnue_id') and (property.gnue_type == 'id'):
+    # If there is a property 'gnue_id' of type 'id' in a class use it for the
+    # primary key
+    if aClass.properties.has_key ("gnue_id"):
+      if aClass.properties ["gnue_id"].gnue_type == "id":
         pk = GSPrimaryKey (table)
-        pk.name = 'gnue_id_pk_' + property.klass.fullName
+        pk.name = "gnue_id_pk_%s" % aClass.fullName
 
-        pkf = GSPKField(pk)
+        pkf = GSPKField (pk)
         pkf.name = 'gnue_id'
           
                   
   # ---------------------------------------------------------------------------
   # Dump all tabledata from a given tablelist
   # ---------------------------------------------------------------------------
-  def createDataList(self, gsdata, tablelist):
-    # get a unique list of all modules enlisted in tablelist
-    modlist = {}
-    for table in tablelist:
-      (module, classname) = Namespace.splitName (table)
-      modlist [module] = 1
+  def __createDataList (self, gsData, tableList):
 
-    # dump all modules enlisted in tablelist
-    moddata = GSTableData (gsdata)
+    # first we need a list of all modules used in tableList
+    modules = {}
+    for table in tableList:
+      modules [Namespace.splitName (table) [0]] = 1
+
+    # dump one row from gnue_module for all items in modules 
+    moddata = GSTableData (gsData)
     moddata.name      = 'gnue_module_dump'
     moddata.tablename = 'gnue_module'
     modrows = GSRows (moddata)
 
-    for module in modlist.keys ():
-      moddef = self._modules [module]
+    for module in modules.keys ():
+      mDef = self.__modules [module]
 
       row = GSRow (modrows)
-      # we use the same sort order here as BaseDictionary.values ()
-      self._buildValue (row, 'gnue_comment', moddef.gnue_comment)
-      self._buildValue (row, 'gnue_id'     , moddef.gnue_id)
-      self._buildValue (row, 'gnue_name'   , moddef.gnue_name)
 
-    # dump all classes enlisted in tablelist
-    tabledata = GSTableData (gsdata)
+      self.__buildValue (row, mDef.gnue_comment)
+      self.__buildValue (row, mDef.gnue_id)
+      self.__buildValue (row, mDef.gnue_name)
+
+    # dump all gnue_class rows for the requested tables
+    tabledata = GSTableData (gsData)
     tabledata.name      = 'gnue_class_dump'
     tabledata.tablename = 'gnue_class'
     tablerows = GSRows (tabledata)
       
     # and all their properties 
-    propdata = GSTableData (gsdata)
+    propdata = GSTableData (gsData)
     propdata.name      = 'gnue_property_dump'
     propdata.tablename = 'gnue_property'
     proprows = GSRows (propdata)
 
-    for tablename in tablelist:
-      classdef = self._classes [tablename]
+    for tablename in tableList:
+      cDef = self.__classes [tablename]
           
       # save tabledata
       row = GSRow (tablerows)              
-      self._buildValue (row, 'gnue_comment', classdef.gnue_comment)
-      self._buildValue (row, 'gnue_id'     , classdef.gnue_id)
-      self._buildValue (row, 'gnue_module' , classdef.gnue_module)
-      self._buildValue (row, 'gnue_name'   , classdef.gnue_name)
+
+      self.__buildValue (row, cDef.gnue_comment)
+      self.__buildValue (row, cDef.gnue_id)
+      self.__buildValue (row, cDef.gnue_module)
+      self.__buildValue (row, cDef.gnue_name)
       
-      for property in classdef.properties.values ():
+      for cProp in cDef.properties.values ():
         # add one field per property
         row = GSRow (proprows)                           
-        self._buildValue (row, 'gnue_class' ,  property.gnue_class)
-        self._buildValue (row, 'gnue_comment', property.gnue_comment)
-        self._buildValue (row, 'gnue_id'    ,  property.gnue_id)
-        self._buildValue (row, 'gnue_length',  int (property.gnue_length))
-        self._buildValue (row, 'gnue_module',  property.gnue_module)
-        self._buildValue (row, 'gnue_name'  ,  property.gnue_name)
-        self._buildValue (row, 'gnue_scale' ,  int (property.gnue_scale))
-        self._buildValue (row, 'gnue_type'  ,  property.gnue_type)
+
+        self.__buildValue (row, cProp.gnue_class)
+        self.__buildValue (row, cProp.gnue_comment)
+        self.__buildValue (row, cProp.gnue_id)
+        self.__buildValue (row, int (cProp.gnue_length))
+        self.__buildValue (row, cProp.gnue_module)
+        self.__buildValue (row, cProp.gnue_name)
+        self.__buildValue (row, int (cProp.gnue_scale))
+        self.__buildValue (row, cProp.gnue_type)
                   
 
   # ---------------------------------------------------------------------------
   # Create a new field in a row and populate it with a value
   # ---------------------------------------------------------------------------
-  def _buildValue(self, row, field, data):
-    val = GSValue (row)
-    GContent (val, "'%s'" % data)
+  def __buildValue (self, row, data):
+    GContent (GSValue (row), "'%s'" % data)
 
+  
+
+  # ---------------------------------------------------------------------------
+  # Load a Schema from a file and store it in the class repository
+  # Parameter: filename:  name of file to load
+  #            overwrite: if true, old class definitions will be removed
+  #            install:   if true, database tables for the class will be 
created
+  # TODO: a) make this code transactional, i.e. first check, if everything can 
+  #          be done without breaks, then execute.
+  #       b) add global class repository locking
+  # ---------------------------------------------------------------------------
+  def loadSchemaFromFile (self, filename, overwrite=0, install=0):
+    input = openResource (filename)
+    schema = GSParser.loadFile (input)
+
+    for table in schema.findChildrenOfType ('GSTable', allowAllChildren = 1):
+      print 'adding Table %s' % table.name
+
+      for field in table.findChildrenOfType ('GSField', allowAllChildren = 1):
+        print '   with field %s:' % field.name
+
+    if overwrite:
+      raise 'Overwrite support not working yet.'
+      
+    if install:
+      # TODO: this job should be done in a quite general way,
+      #       to let the code be reused in reaction on  manual class
+      #       repository changes.
+      raise 'Creation of Schema tables is not supported yet'
+
+
+
 # =============================================================================
 # test program
 # =============================================================================
@@ -231,14 +284,9 @@
 if __name__ == '__main__':
   from gnue.appserver.test import testApp
   
-  app=testApp()
-  
+  app = testApp()
   sm = app.getSessionManager ()
   
   gsdSupp = SchemaSupport (sm.modules, sm.classes)
 
-  gsdSupp.writeSchemaToFile ('AS_schema.gsd')
-  gsdSupp.writeSchemaToFile ('AS_schema2.gsd', ['address_person'])
-
- #  gsdSupp.loadSchemaFromFile('AS_schema.gsd',overwrite=0)
-  
+  gsdSupp.writeSchemaToFile ('AS_Schema.gsd')

Added: trunk/gnue-appserver/src/geasGsdGen.py
===================================================================
--- trunk/gnue-appserver/src/geasGsdGen.py      2004-02-07 11:46:20 UTC (rev 
5077)
+++ trunk/gnue-appserver/src/geasGsdGen.py      2004-02-08 09:31:03 UTC (rev 
5078)
@@ -0,0 +1,91 @@
+# GNU Enterprise Application Server - Gnue Schema Definition Generator
+#
+# Copyright 2001-2004 Free Software Foundation
+#
+# 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
+# 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
+# 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
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import sys
+from gnue.common.apps.GClientApp import *
+from gnue.appserver.geasSessionManager import geasSessionManager 
+from gnue.appserver.classrep.SchemaSupport import *
+from gnue.appserver.classrep.Namespace import *
+
+# =============================================================================
+# Generate GNUe Schema Definition files from appservers class repository 
+# =============================================================================
+
+class geasGsdGen (GClientApp):
+
+  NAME    = "geasGsdGen"
+  VERSION = "0.0.1"
+  COMMAND = "gnue-gsdgen"
+  SUMMARY = _("A tool to create GNUe Schema Definition (gsd) files from ") + \
+            _("the appservers class repository.")
+  USAGE   = "%s %s" % (GClientApp.USAGE, _(" [classname] [classname] [...]"))
+  COMMAND_OPTIONS = [
+    ['output', 'o', 'output-file', True, None, "file",
+      _('Name of the resulting gsd-file')],
+    ['export', 'e', 'export', True, None, "type",
+      _('What to export: "schema", "data", "both". Default is "both"')]
+  ]
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+  def __init__ (self, connections = None):
+    ConfigOptions = {}
+    GClientApp.__init__ (self, connections, 'appserver', ConfigOptions)
+
+
+  # ---------------------------------------------------------------------------
+  # Print a message to stdout, if output is sent to a file
+  # ---------------------------------------------------------------------------
+  def __message (self, text):
+    if self.__filename:
+      print text
+
+  # ---------------------------------------------------------------------------
+  # Main program
+  # ---------------------------------------------------------------------------
+  def run (self):
+    self.__filename = self.OPTIONS ['output']
+    self.__type     = self.OPTIONS ['export']
+
+    self.__message (_("Loading class repository ..."))
+    sm = geasSessionManager (self.connections)
+    sSupport = SchemaSupport (sm.modules, sm.classes)
+
+    self.__message (_("Generating schema definition ..."))
+    try:
+      sSupport.writeSchemaToFile (self.__filename, self.ARGUMENTS, self.__type)
+
+    except Exception, msg:
+      sys.stderr.write (_("Error: %s\n" % msg))
+      sys.exit (1)
+
+
+    self.__message (_("Generation run complete."))
+
+
+
+
+
+if __name__ == "__main__":
+  geasGsdGen ().run ()


Property changes on: trunk/gnue-appserver/src/geasGsdGen.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/gnue-appserver/src/test.py
===================================================================
--- trunk/gnue-appserver/src/test.py    2004-02-07 11:46:20 UTC (rev 5077)
+++ trunk/gnue-appserver/src/test.py    2004-02-08 09:31:03 UTC (rev 5078)
@@ -87,7 +87,7 @@
 
 class testLoginHandler (GLoginHandler.LoginHandler):
   def getLogin (self, *arguments):
-    return {"_username": "gnue", "_password": None}
+    return {"_username": "johannes", "_password": None}
 
 # =============================================================================
 # Let it rock





reply via email to

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