Author: johannes Date: 2005-06-01 07:28:06 -0500 (Wed, 01 Jun 2005) New Revision: 7561
Modified: trunk/gnue-designer/src/base/TemplateBase.py trunk/gnue-designer/src/base/tools/DataSourceEditor.py trunk/gnue-designer/src/base/tools/SchemaNavigator.py trunk/gnue-designer/src/base/tools/SchemaViewer.py trunk/gnue-designer/src/forms/wizards/CreateSchema.py trunk/gnue-designer/src/schema/DiaEditor/VisualEditor.py trunk/gnue-designer/src/schema/Incubator.py trunk/gnue-designer/src/schema/Instance.py trunk/gnue-designer/src/schema/TemplateSupport.py trunk/gnue-designer/src/templates/forms/FormBuilder.py trunk/gnue-designer/src/templates/forms/Simple.py trunk/gnue-designer/src/templates/reports/Labels.py trunk/gnue-designer/src/templates/reports/MailMerge.py trunk/gnue-designer/src/templates/reports/SimpleReport.py trunk/gnue-designer/src/templates/schema/Introspection.py Log: Use GSD-object trees for introspection now Modified: trunk/gnue-designer/src/base/TemplateBase.py =================================================================== --- trunk/gnue-designer/src/base/TemplateBase.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/base/TemplateBase.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -165,35 +165,47 @@ return self._connections.getConnection(connection_name,1) - def GetAvailableSources(self, connection_name): + def GetAvailableSources (self, connection_name): - if not self.__cachedSources.has_key(connection_name): - self.__cachedSources[connection_name] = \ - self.GetTemporaryConnection(connection_name).introspector.find() + if not self.__cachedSources.has_key (connection_name): + self.__cachedSources [connection_name] = tables = \ + self.GetTemporaryConnection (connection_name).behavior.readSchema () - list = [] - for schema in self.__cachedSources[connection_name]: - list.append ((schema.name, - hasattr(schema,'description') and schema.description or schema.name)) - return list + result = [] + if tables is not None: + for table in tables.findChildrenOfType ('GSTable', False, True): + result.append ((table.name, hasattr (table, 'description') and + table.description or table.name)) + return result - def GetSourceSchema(self, connection_name, source_name): - return self.GetTemporaryConnection(connection_name)\ - .introspector.findone(name=source_name) + def GetSourceSchema (self, connection_name, source_name): - def GetAvailableFields(self, connection_name, source_name): - list = [] - source = self.GetSourceSchema(connection_name, source_name) - if source != None: - for schema in source.fields(): - list.append((schema.name, hasattr(schema,'description') \ - and schema.description or schema.name)) + if not connection_name in self.__cachedSources: + self.__cachedSources [connection_name] = \ + self.GetTemporaryConnection (connection_name).behavior.readSchema () - return list + schema = self.__cachedSources [connection_name] + if schema is not None: + for table in schema.findChildrenOfType ('GSTable', False, True): + if table.name.lower () == source_name.lower (): + return table + else: + return None + def GetAvailableFields (self, connection_name, source_name): + result = [] + source = self.GetSourceSchema (connection_name, source_name) + if source is not None: + for field in source.findChildrenOfType ('GSField', False, True): + result.append ((field.name, hasattr (field, 'description') \ + and field.description or field.name)) + + return result + + def GetUniqueName(self, name, limitingObject=None): return self.instance.getUniqueName(name, limitingObject) Modified: trunk/gnue-designer/src/base/tools/DataSourceEditor.py =================================================================== --- trunk/gnue-designer/src/base/tools/DataSourceEditor.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/base/tools/DataSourceEditor.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -571,20 +571,24 @@ c = self.editor.connections.getConnection (conn, True) - schema = c.introspector.findone(name=self.editor.current.table) + schema = c.behavior.readSchema ()(name=self.editor.current.table) + table = None + if schema is not None: + for item in schema.findChildrenOfType ('GSTable', False, True): + if item.name.lower () == self.editor.current.table.lower (): + table = item + break - index = 0 self.list.DeleteAllItems() - if schema: - for field in schema.fields(): + if table: + for field in table.findChildrenOfType ('GSField', False, True): self.list.InsertStringItem(index, field.name) - self.list.SetStringItem(index, SCH_TYPE, - string.upper(field.datatype[0]) + field.datatype[1:]) + self.list.SetStringItem (index, SCH_TYPE, field.type.capitalize ()) self.list.SetStringItem(index, SCH_NATIVE, hasattr(field, 'nativetype') and field.nativetype or '(unknown)') self.list.SetStringItem(index, SCH_REQ, - field.required and "Yes" or "No") + field.nullable and "No" or "Yes") if hasattr(field,'length'): if hasattr(field,'precision') and field.precision > 0: self.list.SetStringItem(index, SCH_SIZE, "%s;%s" % ( @@ -637,8 +641,8 @@ string.join(string.split(string.capwords( \ string.replace(object.name,'_',' '))),''))), "field": object.name, - "datatype": object.datatype, - "required" : object.required, + "datatype": object.type, + "required" : not object.nullable, } if hasattr(object,'length') and object.length: Modified: trunk/gnue-designer/src/base/tools/SchemaNavigator.py =================================================================== --- trunk/gnue-designer/src/base/tools/SchemaNavigator.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/base/tools/SchemaNavigator.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -239,45 +239,38 @@ self.expanded = 1 connection = self.navigator.connections.getConnection(self.connection, login=1) - schemaTypes = connection.introspector.types[:] + schema = connection.behavior.readSchema () - if not schemaTypes: + if schema is None: return - schemaTypes.sort() - for schema, name, keep in schemaTypes: - if keep: - SchemaTypeNode(self.navigator, self.tree, self.node, - introspector=connection.introspector, type=schema, name=name) + for tables in schema.findChildrenOfType ('GSTables', False, True): + SchemaTypeNode (self.navigator, self.tree, self.node, tables = tables) - def getLabel(self): + + def getLabel (self): return self.connection - def getColumn(self, i=0): - data = self.navigator.connections.getConnectionParameters(self.connection) + def getColumn (self, i=0): + data = self.navigator.connections.getConnectionParameters (self.connection) try: return data['comment'] + ' (' + data['provider'] + ')' except: return '(' + data['provider'] + ')' -class SchemaTypeNode(Node): - def getLabel(self): - return self.name - def getColumn(self, i=0): +class SchemaTypeNode (Node): + def getLabel (self): + return self.tables.name + def getColumn (self, i=0): return "" - def expand(self): + def expand (self): self.expanded = 1 - tree = self.tree - schemas = self.introspector.find(type=self.type) - if not schemas: - return - schemas.sort() - for schema in schemas: - TableNode(self.navigator, self.tree, self.node, - schema=schema) + for table in self.tables.findChildrenOfType ('GSTable', False, True): + TableNode (self.navigator, self.tree, self.node, schema = table) + class TableNode(Node): def getLabel(self): return self.schema.name @@ -285,11 +278,11 @@ return "" def expand(self): self.expanded = 1 - for field in self.schema.fields(): - FieldNode(self.navigator, self.tree, self.node, field=field) + for field in self.schema.findChildrenOfType ('GSField', False, True): + FieldNode (self.navigator, self.tree, self.node, field = field) -class FieldNode(Node): +class FieldNode (Node): isleaf = 1 def getLabel(self): return self.field.name @@ -297,19 +290,19 @@ def getColumn(self): rv = "" data = [] - rv += self.field.datatype.capitalize() + rv += self.field.type.capitalize () try: - data.append(str(self.field.length)) + data.append (str (self.field.length)) except: pass try: - data.append(str(self.field.precision)) + data.append (str (self.field.precision)) except: pass ## if data: ## rv += '; Size: ' + string.join(data,',') - if self.field.required: + if not self.field.nullable: rv += "; Not Null" return rv Modified: trunk/gnue-designer/src/base/tools/SchemaViewer.py =================================================================== --- trunk/gnue-designer/src/base/tools/SchemaViewer.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/base/tools/SchemaViewer.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -133,24 +133,29 @@ # Create a cache by connection to conserve database calls try: - schemaTypes, schemas = self.connectionCache[conn] + types, tables = self.connectionCache[conn] except KeyError: c = self.connections.getConnection (conn, True) - schemaTypes = c.introspector.types - schemas = c.introspector.find() - schemas.sort() - self.connectionCache[conn] = (schemaTypes, schemas) + gstree = c.behavior.readSchema () + types = [] + tables = None + if gstree is not None: + for item in gstree.findChildrenOfType ('GSTables', False, True): + types.append (item.name) + tables = gstree.findChildrenOfType ('GSTable', False, True) + self.connectionCache[conn] = (types, tables) + + index = 0 self.list.DeleteAllItems() - for schema in schemas: + for schema in tables: self.list.InsertStringItem(index, schema.name) - self.list.SetStringItem(index, 1, - schema.type) + self.list.SetStringItem(index, 1, schema.type) self.list.SetItemData(index, index) index += 1 Modified: trunk/gnue-designer/src/forms/wizards/CreateSchema.py =================================================================== --- trunk/gnue-designer/src/forms/wizards/CreateSchema.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/forms/wizards/CreateSchema.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -31,7 +31,7 @@ from gnue.designer.forms.TemplateSupport import * from gnue.designer import VERSION -from gnue.common.schema.Objects import * +from gnue.common.datasources import GSchema import string @@ -104,8 +104,8 @@ def Finalize(self): self.tablelist = {} - self.schema = GSSchema() - self.gstables = GSTables(self.schema) + self.schema = GSchema.GSSchema() + self.gstables = GSchema.GSTables(self.schema) # Create Tables out of <datasource> tags self.form.walk(self.CreateTables) @@ -134,10 +134,10 @@ # add the table # - newtable = GSTable(self.gstables) + newtable = GSchema.GSTable(self.gstables) newtable.name=obj.table - GSFields(newtable) - GSConstraints(newtable) + GSchema.GSFields(newtable) + GSchema.GSConstraints(newtable) self.tablelist[string.lower(obj.name)]=newtable else: @@ -239,13 +239,14 @@ table=self.tablelist[string.lower(obj.name)] # create a foreign key on this table - newconstraint=GSConstraint(table.findChildOfType('GSConstraints')) + newconstraint=GSchema.GSConstraint ( \ + table.findChildOfType ('GSConstraints')) newconstraint.name="fk_%s_%s" % (obj.table,obj.detaillink) newconstraint.type="foreignkey" - nfk_field=GSConstraintField(newconstraint) + nfk_field=GSchema.GSConstraintField(newconstraint) nfk_field.name=obj.detaillink - nfk_ref=GSConstraintRef(newconstraint) + nfk_ref=GSchema.GSConstraintRef(newconstraint) nfk_ref.name=obj.masterlink # create a field for that key, use string type for now @@ -261,9 +262,9 @@ oldpkey=mtable.findChildOfType("GSPKField") if oldpkey==None: - pkey=GSPrimaryKey(mtable) + pkey=GSchema.GSPrimaryKey(mtable) pkey.name="pk_%s_%s" % (mtable.name,obj.masterlink) - pkeyf=GSPKField(pkey) + pkeyf=GSchema.GSPKField(pkey) pkeyf.name=obj.masterlink # add field to master table, using default type @@ -297,7 +298,7 @@ return # create field - newfield = GSField(fields) + newfield = GSchema.GSField(fields) newfield.name=fieldname newfield.type=type if length!=None: Modified: trunk/gnue-designer/src/schema/DiaEditor/VisualEditor.py =================================================================== --- trunk/gnue-designer/src/schema/DiaEditor/VisualEditor.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/schema/DiaEditor/VisualEditor.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -29,7 +29,6 @@ from wxPython.wx import * from VisualTable import * -from gnue.common.schema.Objects import * from gnue.designer.base.ToolBase import * class VisualEditor (ToolBase): Modified: trunk/gnue-designer/src/schema/Incubator.py =================================================================== --- trunk/gnue-designer/src/schema/Incubator.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/schema/Incubator.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -28,11 +28,11 @@ # from gnue.common.apps import GDebug -from gnue.common.schema import GSParser, Objects +from gnue.common.datasources import GSchema from gnue.designer.base.Incubator import BaseIncubator class Incubator(BaseIncubator): - elements = GSParser.getXMLelements() + elements = GSchema.getXMLelements() - \ No newline at end of file + Modified: trunk/gnue-designer/src/schema/Instance.py =================================================================== --- trunk/gnue-designer/src/schema/Instance.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/schema/Instance.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -29,7 +29,7 @@ from gnue.designer.schema import properties as schemaProperties from gnue.designer.base.Instance import BaseInstance -from gnue.common.schema import GSParser, Objects +from gnue.common.datasources import GSchema from Incubator import Incubator import wizards @@ -56,21 +56,21 @@ def loadBuffer(self, buffer): - schema = GSParser.loadFile (buffer, self, initialize=0) + schema = GSchema.loadFile (buffer, self, initialize=0) schema.name = 'schema' return schema def loadEmpty(self, style=None): - schema = Objects.GSSchema() + schema = GSchema.GSSchema() schema.title = "Untitled schema" schema.name = 'schema' - Objects.GSTables(schema) + GSchema.GSTables(schema) return schema def inventoryObject(self, object): - if isinstance(object, Objects.GSTables): + if isinstance(object, GSchema.GSTables): self.tables = object elif object._type == 'GSTable': self._tableMappings[object.name] = object Modified: trunk/gnue-designer/src/schema/TemplateSupport.py =================================================================== --- trunk/gnue-designer/src/schema/TemplateSupport.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/schema/TemplateSupport.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -28,11 +28,11 @@ # from gnue.designer.base.TemplateBase import * -from gnue.common.schema import Objects +from gnue.common.datasources import GSchema # TODO def createRootObject(instance): - return Objects.GSSchema() + return GSchema.GSSchema () Modified: trunk/gnue-designer/src/templates/forms/FormBuilder.py =================================================================== --- trunk/gnue-designer/src/templates/forms/FormBuilder.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/forms/FormBuilder.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -54,8 +54,14 @@ # The template parser will initially # call GetStep(FIRST_STEP). FIRST_STEP = '0' + TYPEMAP = {'date' : 'date', + 'time' : 'date', + 'datetime': 'date', + 'boolean' : 'boolean', + 'number' : 'number'} + ############### # # Initialize any runtime variables @@ -423,7 +429,7 @@ # because we want to keep in the order that the user # specified fields = {} - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): if field.name in self.variables['tablefields%s' % count]: fields[field.name] = field @@ -463,7 +469,7 @@ attrs={ 'name': "fld%s" % fieldKey, 'field': field.name, - 'typecast': field.datatype } + 'typecast': self.TYPEMAP.get (field.type, 'text')} # If we have a length for the field, use this as the maxLength # for the entry. Also, adjust the display width if necessary. Modified: trunk/gnue-designer/src/templates/forms/Simple.py =================================================================== --- trunk/gnue-designer/src/templates/forms/Simple.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/forms/Simple.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -43,8 +43,13 @@ # -class SimpleFormTemplate(FormTemplate): +class SimpleFormTemplate (FormTemplate): + TYPEMAP = {'date' : 'date', + 'time' : 'date', + 'datetime': 'date', + 'boolean' : 'boolean', + 'number' : 'number'} # The first step in our wizard. # The template parser will initially @@ -212,7 +217,7 @@ # because we want to keep in the order that the user # specified fields = {} - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): if field.name in self.variables['fields']: fields[field.name] = field @@ -252,7 +257,7 @@ attrs={ 'name': "fld%s" % fieldKey, 'field': field.name, - 'typecast': field.datatype } + 'typecast': self.TYPEMAP.get (field.type, 'text')} # If we have a length for the field, use this as the maxLength # for the entry. Also, adjust the display width if necessary. Modified: trunk/gnue-designer/src/templates/reports/Labels.py =================================================================== --- trunk/gnue-designer/src/templates/reports/Labels.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/reports/Labels.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -171,7 +171,7 @@ # because we want to keep in the order that the user # specified fields = {} - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): if field.name in self.variables['fields']: fields[field.name] = field Modified: trunk/gnue-designer/src/templates/reports/MailMerge.py =================================================================== --- trunk/gnue-designer/src/templates/reports/MailMerge.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/reports/MailMerge.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -169,7 +169,7 @@ # because we want to keep in the order that the user # specified fields = {} - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): if field.name in self.variables['fields']: fields[field.name] = field Modified: trunk/gnue-designer/src/templates/reports/SimpleReport.py =================================================================== --- trunk/gnue-designer/src/templates/reports/SimpleReport.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/reports/SimpleReport.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -176,7 +176,7 @@ # because we want to keep in the order that the user # specified fields = {} - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): if field.name in self.variables['fields']: fields[field.name] = field @@ -188,10 +188,12 @@ for name in self.variables['fields']: field = fields[name] - attrs = {'width':field.length} - if field.datatype == 'number': + attrs = {} + if hasattr (field, 'length'): + attrs ['width'] = field.length + if field.type == 'number': attrs['align'] = "right" - elif field.datatype == 'date': + elif field.type in ['date', 'time', 'datetime']: attrs['align'] = "center" out_colhead = self.AddElement('out:colhead', out_tablehead, attrs, content=field.name) @@ -202,9 +204,9 @@ for name in self.variables['fields']: field = fields[name] attrs = {} - if field.datatype == 'number': + if field.type == 'number': attrs['align'] = "right" - elif field.datatype == 'date': + elif field.type in ['date', 'time', 'datetime']: attrs['align'] = "center" out_col = self.AddElement('out:col', out_row, attrs) self.AddElement('field', out_col, {'name':field.name}) Modified: trunk/gnue-designer/src/templates/schema/Introspection.py =================================================================== --- trunk/gnue-designer/src/templates/schema/Introspection.py 2005-06-01 12:27:27 UTC (rev 7560) +++ trunk/gnue-designer/src/templates/schema/Introspection.py 2005-06-01 12:28:06 UTC (rev 7561) @@ -134,6 +134,9 @@ # Create the tables and fields... print "Adding <tables>" + # FIXME: this code is kind of obsolete, since self.GetSourceSchema already + # returns a complete GSTable object tree. So the only thing needed + # here would be add a clone of that tree to the local object tree tables = self.root.findChildOfType('GSTables') #self.AddElement('tables', self.root, {}) @@ -146,26 +149,27 @@ { 'name': tablename } ) try: - primarykeys = schema.primarykey + primarykeys = schema.findChildOfType ('GSPrimaryKey') except: - primarykeys = [] + primarykeys = None fields = self.AddElement('fields', table, {}) # Add each field - for field in schema.fields(): + for field in schema.findChildrenOfType ('GSField', False, True): print " Adding <field> %s" % field.name attrs = { 'name': field.name, - 'type': field.datatype } + 'type': field.type } # Add length if appropriate for this datatype + # FIXME: this should be handled much more cleaner !!! try: - if field.datatype != 'date': + if field.type != 'date': attrs['length'] = int(field.length) except AttributeError: - if field.datatype == 'number': + if field.type == 'number': attrs['length'] = 12 - elif field.datatype == 'text': + elif field.type == 'text': attrs['length'] = 200 # ... precision @@ -176,7 +180,7 @@ # Add length if appropriate for this datatype try: - attrs['nullable'] = not field.required + attrs['nullable'] = field.nullable except AttributeError: attrs['nullable'] = 1 @@ -202,10 +206,12 @@ if primarykeys: pk = self.AddElement ('primarykey', table, {}) pk.name='pk_%s' % tablename - for field in primarykeys: + for field in primarykeys.findChildrenOfType ('GSPKField', False, True): self.AddElement('pkfield', pk, {'name': field}) # Add misc tags + # TODO: a GSTable instance as returned by GetSourceSchema () might + # already contain indices and constraints too! self.AddElement ('constraints', table, {}) self.AddElement ('indexes', table, {}) _______________________________________________ Commit-gnue mailing list Commit-gnue@gnu.org http://lists.gnu.org/mailman/listinfo/commit-gnue