Update of /cvsroot/webware/Webware/MiddleKit/Design
In directory usw-pr-cvs1:/tmp/cvs-serv18045/MiddleKit/Design
Modified Files:
CodeGenerator.py Generate.py MSSQLSQLGenerator.py
PythonGenerator.py SQLGenerator.py
Log Message:
Changed doc strings to use ''' instead of """
Index: CodeGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/CodeGenerator.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CodeGenerator.py 13 Feb 2001 04:42:52 -0000 1.1
--- CodeGenerator.py 20 Jun 2002 17:47:45 -0000 1.2
***************
*** 1,3 ****
! '''
CodeGenerator.py
--- 1,3 ----
! """
CodeGenerator.py
***************
*** 19,23 ****
* Inheritance of generators is supported
* Class inheritance (like Klasses inheriting ModelObject works)
! '''
--- 19,23 ----
* Inheritance of generators is supported
* Class inheritance (like Klasses inheriting ModelObject works)
! """
***************
*** 32,36 ****
def name(self):
! ''' Returns the name of the generator for informational purposes. The name the is the class name. '''
return self.__class__.__name__
--- 32,36 ----
def name(self):
! """ Returns the name of the generator for informational purposes. The name the is the class name. """
return self.__class__.__name__
Index: Generate.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/Generate.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Generate.py 3 May 2002 14:26:28 -0000 1.6
--- Generate.py 20 Jun 2002 17:47:45 -0000 1.7
***************
*** 1,8 ****
#!/usr/bin/env python
! '''
Generate.py
> python Generate.py -h
! '''
--- 1,8 ----
#!/usr/bin/env python
! """
Generate.py
> python Generate.py -h
! """
***************
*** 12,19 ****
def FixPathForMiddleKit(verbose=0):
! '''
Enhances sys.path so that Generate.py can import MiddleKit.whatever.
We *always* enhance the sys.path so that Generate.py is using the MiddleKit that contains him, as opposed to whatever happens to be found first in the Python path. That's an subtle but important feature for those of us who sometimes have more than one MiddleKit on our systems.
! '''
v = verbose
import os, sys
--- 12,19 ----
def FixPathForMiddleKit(verbose=0):
! """
Enhances sys.path so that Generate.py can import MiddleKit.whatever.
We *always* enhance the sys.path so that Generate.py is using the MiddleKit that contains him, as opposed to whatever happens to be found first in the Python path. That's an subtle but important feature for those of us who sometimes have more than one MiddleKit on our systems.
! """
v = verbose
import os, sys
***************
*** 135,139 ****
def generate(self, pyClass, model, outdir):
! ''' Generates code using the given class, model and output directory. The pyClass may be a string, in which case a module of the same name is imported and the class extracted from that. The model may be a string, in which case it is considered a filename of a model. '''
if type(pyClass) is types.StringType:
module = __import__(pyClass, globals())
--- 135,139 ----
def generate(self, pyClass, model, outdir):
! """ Generates code using the given class, model and output directory. The pyClass may be a string, in which case a module of the same name is imported and the class extracted from that. The model may be a string, in which case it is considered a filename of a model. """
if type(pyClass) is types.StringType:
module = __import__(pyClass, globals())
Index: MSSQLSQLGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/MSSQLSQLGenerator.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** MSSQLSQLGenerator.py 13 Jun 2002 04:44:58 -0000 1.6
--- MSSQLSQLGenerator.py 20 Jun 2002 17:47:45 -0000 1.7
***************
*** 30,34 ****
def dropDatabaseSQL(self, dbName):
! '''
Rather than drop the database, I prefer to drop just the tables.
The reason is that the database in MSSQL can contain users and diagrams that would then need to be re-added or re-created
--- 30,34 ----
def dropDatabaseSQL(self, dbName):
! """
Rather than drop the database, I prefer to drop just the tables.
The reason is that the database in MSSQL can contain users and diagrams that would then need to be re-added or re-created
***************
*** 36,40 ****
What is even worse is that identity resets behave differently depending on whether data has existed in them at any given point.
Its safer to drop the table. dr 4-11-2001
! '''
strList = []
strList.append('use %s\ngo\n' % dbName)
--- 36,40 ----
What is even worse is that identity resets behave differently depending on whether data has existed in them at any given point.
Its safer to drop the table. dr 4-11-2001
! """
strList = []
strList.append('use %s\ngo\n' % dbName)
***************
*** 52,58 ****
def createDatabaseSQL(self, dbName):
! '''
Creates the database only if it does not already exist
! '''
return 'Use Master\n' + 'go\n\n' + "if not exists( select * from master.dbo.sysdatabases where name = N'%s' ) create database %s; \n" % (dbName, dbName)
--- 52,58 ----
def createDatabaseSQL(self, dbName):
! """
Creates the database only if it does not already exist
! """
return 'Use Master\n' + 'go\n\n' + "if not exists( select * from master.dbo.sysdatabases where name = N'%s' ) create database %s; \n" % (dbName, dbName)
***************
*** 91,95 ****
def writeKeyValue(self, out, key, value):
! ''' Used by willWriteSQL(). '''
key = ljust(key, 12)
out.write('# %s = %s\n' % (key, value))
--- 91,95 ----
def writeKeyValue(self, out, key, value):
! """ Used by willWriteSQL(). """
key = ljust(key, 12)
out.write('# %s = %s\n' % (key, value))
***************
*** 162,168 ****
def primaryKeySQLDef(self, generator):
! '''
! Returns a one liner that becomes part of the CREATE statement for creating the primary key of the table. SQL generators often override this mix-in method to customize the creation of the primary key for their SQL variant. This method should use self.sqlIdName() and often ljust()s it by self.maxNameWidth().
! '''
# print("print 'Creating table %s'\n" % name)
--- 162,174 ----
def primaryKeySQLDef(self, generator):
! """
! Returns a one liner that becomes part of the CREATE
! statement for creating the primary key of the
! table. SQL generators often override this mix-in
! method to customize the creation of the primary key
! for their SQL variant. This method should use
! self.sqlIdName() and often ljust()s it by
! self.maxNameWidth().
! """
# print("print 'Creating table %s'\n" % name)
Index: PythonGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/PythonGenerator.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** PythonGenerator.py 7 May 2002 06:42:07 -0000 1.20
--- PythonGenerator.py 20 Jun 2002 17:47:46 -0000 1.21
***************
*** 50,54 ****
def writePy(self, generator, out=sys.stdout):
! ''' Writes the Python code to define a table for the class. The target can be a file or a filename. '''
if type(out) is StringType:
out = open(out, 'w')
--- 50,54 ----
def writePy(self, generator, out=sys.stdout):
! """ Writes the Python code to define a table for the class. The target can be a file or a filename. """
if type(out) is StringType:
out = open(out, 'w')
***************
*** 167,171 ****
def writePyAccessors(self):
! ''' Write Python accessors for attributes simply by asking each one to do so. '''
out = self._pyOut
for attr in self.attrs():
--- 167,171 ----
def writePyAccessors(self):
! """ Write Python accessors for attributes simply by asking each one to do so. """
out = self._pyOut
for attr in self.attrs():
***************
*** 176,180 ****
def defaultValue(self):
! ''' Returns the default value as a legal Pythonic value. '''
if self.has_key('Default'):
default = self['Default']
--- 176,180 ----
def defaultValue(self):
! """ Returns the default value as a legal Pythonic value. """
if self.has_key('Default'):
default = self['Default']
***************
*** 191,199 ****
# @@ 2000-11-25 ce: consider moving this to Core
# @@ 2000-11-25 ce: also, this might be usable in the store
! '''
Returns a bona fide Python value given a string. Invokers should never pass None or blank strings.
Used by at least defaultValue().
Subclass responsibility.
! '''
raise SubclassResponsibilityError
--- 191,199 ----
# @@ 2000-11-25 ce: consider moving this to Core
# @@ 2000-11-25 ce: also, this might be usable in the store
! """
Returns a bona fide Python value given a string. Invokers should never pass None or blank strings.
Used by at least defaultValue().
Subclass responsibility.
! """
raise SubclassResponsibilityError
***************
*** 438,442 ****
def defaultValue(self):
! ''' Returns the default value as a legal Pythonic value. '''
assert not self.get('Default', 0), 'Cannot have default values for lists.'
return []
--- 438,442 ----
def defaultValue(self):
! """ Returns the default value as a legal Pythonic value. """
assert not self.get('Default', 0), 'Cannot have default values for lists.'
return []
***************
*** 466,474 ****
def writePyGet(self, out, names):
! ''' Subclass responsibility. '''
raise SubclassResponsibility
def writePySet(self, out, names=None):
! ''' Raises an exception in order to ensure that our inherited "PySet" code generation is used. '''
raise AssertionError, 'Lists do not have a set method.'
--- 466,474 ----
def writePyGet(self, out, names):
! """ Subclass responsibility. """
raise SubclassResponsibility
def writePySet(self, out, names=None):
! """ Raises an exception in order to ensure that our inherited "PySet" code generation is used. """
raise AssertionError, 'Lists do not have a set method.'
Index: SQLGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/SQLGenerator.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** SQLGenerator.py 31 Mar 2002 06:56:09 -0000 1.23
--- SQLGenerator.py 20 Jun 2002 17:47:46 -0000 1.24
***************
*** 8,12 ****
class SQLGenerator(CodeGenerator):
! '''
This class and its associated mix-ins are responsible for generating:
- Create.sql
--- 8,12 ----
class SQLGenerator(CodeGenerator):
! """
This class and its associated mix-ins are responsible for generating:
- Create.sql
***************
*** 32,36 ****
StringAttr
EnumAttr
! '''
def dbName(self):
--- 32,36 ----
StringAttr
EnumAttr
! """
def dbName(self):
***************
*** 62,69 ****
def sqlSupportsDefaultValues(self):
! '''
Subclasses must override to return 1 or 0, indicating their SQL variant supports DEFAULT <value> in the CREATE statement.
Subclass responsibility.
! '''
return SubclassResponsibility
--- 62,69 ----
def sqlSupportsDefaultValues(self):
! """
Subclasses must override to return 1 or 0, indicating their SQL variant supports DEFAULT <value> in the CREATE statement.
Subclass responsibility.
! """
return SubclassResponsibility
***************
*** 86,90 ****
def dbName(self):
! ''' Returns the name of the database, which is currently always equal to self.name(). '''
return self.name()
--- 86,90 ----
def dbName(self):
! """ Returns the name of the database, which is currently always equal to self.name(). """
return self.name()
***************
*** 171,175 ****
def unquote(self, string):
! ''' Removes preceding and trailing quotes. This is a utility method for writeInsertSamplesSQLForLines(). '''
if string:
if string.startswith('"') and string.endswith('"'):
--- 171,175 ----
def unquote(self, string):
! """ Removes preceding and trailing quotes. This is a utility method for writeInsertSamplesSQLForLines(). """
if string:
if string.startswith('"') and string.endswith('"'):
***************
*** 178,182 ****
def areFieldsBlank(self, fields):
! ''' Utility method for writeInsertSamplesSQLForLines(). '''
if len(fields)==0:
return 1
--- 178,182 ----
def areFieldsBlank(self, fields):
! """ Utility method for writeInsertSamplesSQLForLines(). """
if len(fields)==0:
return 1
***************
*** 196,209 ****
def auxiliaryTableNames(self):
! ''' Returns a list of table names in addition to the tables that hold objects. One popular user of this method is dropTablesSQL(). '''
return ['_MKClassIds']
def writeKeyValue(self, out, key, value):
! ''' Used by willCreateWriteSQL(). '''
key = key.ljust(12)
out.write('# %s = %s\n' % (key, value))
def writeCreateSQL(self, generator, out):
! ''' Writes the SQL to define the tables for a set of classes. The target can be a file or a filename. '''
if type(out) is StringType:
out = open(out, 'w')
--- 196,209 ----
def auxiliaryTableNames(self):
! """ Returns a list of table names in addition to the tables that hold objects. One popular user of this method is dropTablesSQL(). """
return ['_MKClassIds']
def writeKeyValue(self, out, key, value):
! """ Used by willCreateWriteSQL(). """
key = key.ljust(12)
out.write('# %s = %s\n' % (key, value))
def writeCreateSQL(self, generator, out):
! """ Writes the SQL to define the tables for a set of classes. The target can be a file or a filename. """
if type(out) is StringType:
out = open(out, 'w')
***************
*** 250,282 ****
def dropDatabaseSQL(self, dbName):
! '''
Returns SQL code that will remove the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! '''
raise SubclassResponsibilityError
def dropTablesSQL(self):
! '''
Returns SQL code that will remove each of the tables in the database.
Used by willWriteCreateSQL().
Subclass responsibility.
! '''
raise SubclassResponsibilityError
def createDatabaseSQL(self, dbName):
! '''
Returns SQL code that will create the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! '''
raise SubclassResponsibilityError
def useDatabaseSQL(self, dbName):
! '''
Returns SQL code that will use the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! '''
raise SubclassResponsibilityError
--- 250,282 ----
def dropDatabaseSQL(self, dbName):
! """
Returns SQL code that will remove the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! """
raise SubclassResponsibilityError
def dropTablesSQL(self):
! """
Returns SQL code that will remove each of the tables in the database.
Used by willWriteCreateSQL().
Subclass responsibility.
! """
raise SubclassResponsibilityError
def createDatabaseSQL(self, dbName):
! """
Returns SQL code that will create the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! """
raise SubclassResponsibilityError
def useDatabaseSQL(self, dbName):
! """
Returns SQL code that will use the database with the given name.
Used by willWriteCreateSQL().
Subclass responsibility.
! """
raise SubclassResponsibilityError
***************
*** 312,319 ****
def writeDeleteAllRecords(self, generator, file):
! '''
Writes a delete statement for each data table in the model. This is used for InsertSamples.sql to wipe out all data prior to inserting sample values.
SQL generators rarely have to customize this method.
! '''
wr = file.write
if 0:
--- 312,319 ----
def writeDeleteAllRecords(self, generator, file):
! """
Writes a delete statement for each data table in the model. This is used for InsertSamples.sql to wipe out all data prior to inserting sample values.
SQL generators rarely have to customize this method.
! """
wr = file.write
if 0:
***************
*** 368,381 ****
def primaryKeySQLDef(self, generator):
! '''
Returns a one liner that becomes part of the CREATE statement for creating the primary key of the table. SQL generators often override this mix-in method to customize the creation of the primary key for their SQL variant. This method should use self.sqlIdName() and often ljust()s it by self.maxNameWidth().
! '''
return ' %s int not null primary key,\n' % self.sqlIdName().ljust(self.maxNameWidth())
def deletedSQLDef(self, generator):
! '''
Returns a one liner that becomes part of the CREATE statement for creating the deleted timestamp field of the table.
This is used if DeleteBehavior is set to "mark".
! '''
return ' %s datetime,\n' % ('deleted'.ljust(self.maxNameWidth()))
--- 368,381 ----
def primaryKeySQLDef(self, generator):
! """
Returns a one liner that becomes part of the CREATE statement for creating the primary key of the table. SQL generators often override this mix-in method to customize the creation of the primary key for their SQL variant. This method should use self.sqlIdName() and often ljust()s it by self.maxNameWidth().
! """
return ' %s int not null primary key,\n' % self.sqlIdName().ljust(self.maxNameWidth())
def deletedSQLDef(self, generator):
! """
Returns a one liner that becomes part of the CREATE statement for creating the deleted timestamp field of the table.
This is used if DeleteBehavior is set to "mark".
! """
return ' %s datetime,\n' % ('deleted'.ljust(self.maxNameWidth()))
***************
*** 402,412 ****
def hasSQLColumn(self):
! ''' Returns true if the attribute has a direct correlating SQL column in it's class' SQL table definition. Most attributes do. Those of type list do not. '''
return not self.get('isDerived', 0)
def sampleValue(self, value):
! ''' Returns a string suitable for a SQL insert statement including any necessary SQL syntax. Subclasses should override to perform type checking and handle any special capabilities.
The invoker of this method already strips preceding and trailing whitespace, as well detects blanks as NULLs.
! '''
# @@ 2001-02-20 ce: restructure this
# sqlValue() instead of sampleValue()
--- 402,412 ----
def hasSQLColumn(self):
! """ Returns true if the attribute has a direct correlating SQL column in it's class' SQL table definition. Most attributes do. Those of type list do not. """
return not self.get('isDerived', 0)
def sampleValue(self, value):
! """ Returns a string suitable for a SQL insert statement including any necessary SQL syntax. Subclasses should override to perform type checking and handle any special capabilities.
The invoker of this method already strips preceding and trailing whitespace, as well detects blanks as NULLs.
! """
# @@ 2001-02-20 ce: restructure this
# sqlValue() instead of sampleValue()
***************
*** 513,521 ****
def sqlType(self):
! '''
Subclass responsibility.
Subclasses should take care that if self['Max']==self['Min'] then the "char" type is preferred over "varchar".
Also, most (if not all) SQL databases require different types depending on the length of the string.
! '''
raise SubclassResponsibilityError
--- 513,521 ----
def sqlType(self):
! """
Subclass responsibility.
Subclasses should take care that if self['Max']==self['Min'] then the "char" type is preferred over "varchar".
Also, most (if not all) SQL databases require different types depending on the length of the string.
! """
raise SubclassResponsibilityError
***************
*** 554,558 ****
def sampleValue(self, value):
! ''' Obj ref sample data format is "Class.serialNum", such as "Thing.3". If the Class and period are missing, then the obj ref's type is assumed. '''
parts = value.split('.')
if len(parts)==2:
--- 554,558 ----
def sampleValue(self, value):
! """ Obj ref sample data format is "Class.serialNum", such as "Thing.3". If the Class and period are missing, then the obj ref's type is assumed. """
parts = value.split('.')
if len(parts)==2:
|