Update of /cvsroot/webware/Webware/MiddleKit/Design
In directory sc8-pr-cvs1:/tmp/cvs-serv5214/Design
Modified Files:
Generate.py PythonGenerator.py SQLGenerator.py
Log Message:
- allow class models to be in .xls format
- be more friendly towards Unicode strings in the model
Index: Generate.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/Generate.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Generate.py 6 Mar 2003 18:06:31 -0000 1.8
--- Generate.py 8 Dec 2003 06:08:40 -0000 1.9
***************
*** 9,12 ****
--- 9,13 ----
import os, string, sys, types
from getopt import getopt
+ from MiddleKit import StringTypes
***************
*** 136,144 ****
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())
pyClass = getattr(module, pyClass)
generator = pyClass()
! if type(model) is types.StringType:
generator.readModelFileNamed(model, havePythonClasses=0)
else:
--- 137,145 ----
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 isinstance(pyClass, StringTypes):
module = __import__(pyClass, globals())
pyClass = getattr(module, pyClass)
generator = pyClass()
! if isinstance(model, StringTypes):
generator.readModelFileNamed(model, havePythonClasses=0)
else:
Index: PythonGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/PythonGenerator.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** PythonGenerator.py 6 Nov 2003 08:51:20 -0000 1.26
--- PythonGenerator.py 8 Dec 2003 06:08:40 -0000 1.27
***************
*** 55,59 ****
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')
close = 1
--- 55,59 ----
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 isinstance(out, StringTypes):
out = open(out, 'w')
close = 1
***************
*** 350,354 ****
out.write('''\
if value is not None:
! if type(value) is not types.StringType:
raise TypeError, 'expecting string type, but got value %r of type %r instead' % (value, type(value))
''')
--- 350,354 ----
out.write('''\
if value is not None:
! if not isinstance(value, types.StringType):
raise TypeError, 'expecting string type, but got value %r of type %r instead' % (value, type(value))
''')
***************
*** 364,368 ****
out.write('''\
if value is not None:
! if type(value) is not types.StringType:
raise TypeError, 'expecting string type for enum, but got value %%r of type %%r instead' %% (value, type(value))
attr = self.klass().lookupAttr('%s')
--- 364,368 ----
out.write('''\
if value is not None:
! if not isinstance(value, types.StringType):
raise TypeError, 'expecting string type for enum, but got value %%r of type %%r instead' %% (value, type(value))
attr = self.klass().lookupAttr('%s')
***************
*** 393,397 ****
# no DateTime, use strings
if value is not None:
! if type(value) is not types.StringType:
raise TypeError, 'expecting string type, but got value %r of type %r instead' % (value, type(value))
''')
--- 393,397 ----
# no DateTime, use strings
if value is not None:
! if isinstance(value, StringTypes):
raise TypeError, 'expecting string type, but got value %r of type %r instead' % (value, type(value))
''')
Index: SQLGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/SQLGenerator.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** SQLGenerator.py 9 Mar 2003 00:14:33 -0000 1.33
--- SQLGenerator.py 8 Dec 2003 06:08:40 -0000 1.34
***************
*** 2,7 ****
import os, sys
from glob import glob
- from types import StringType
from time import asctime, localtime, time
from MiddleKit.Core.ObjRefAttr import objRefJoin
from MiscUtils import CSVParser
--- 2,7 ----
import os, sys
from glob import glob
from time import asctime, localtime, time
+ from MiddleKit import StringTypes
from MiddleKit.Core.ObjRefAttr import objRefJoin
from MiscUtils import CSVParser
***************
*** 12,19 ****
self._line = line
self._error = error
!
def output(self,filename):
print '%s:%d: %s' % ( filename, self._line, self._error )
!
class SQLGenerator(CodeGenerator):
--- 12,19 ----
self._line = line
self._error = error
!
def output(self,filename):
print '%s:%d: %s' % ( filename, self._line, self._error )
!
class SQLGenerator(CodeGenerator):
***************
*** 190,198 ****
value = attr.sampleValue(value)
# print 'Attr: %s, Value: %s' % (attr,value)
! if type(value) is not StringType:
print 'attr:', attr
print 'value:', value
print 'type of value:', type(value)
! assert type(value) is StringType
assert value # value cannot be blank
values[i] = value
--- 190,198 ----
value = attr.sampleValue(value)
# print 'Attr: %s, Value: %s' % (attr,value)
! if not isinstance(value, StringTypes):
print 'attr:', attr
print 'value:', value
print 'type of value:', type(value)
! assert isinstance(value, StringTypes)
assert value # value cannot be blank
values[i] = value
***************
*** 233,237 ****
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')
close = 1
--- 233,237 ----
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 isinstance(out, StringTypes):
out = open(out, 'w')
close = 1
***************
*** 326,330 ****
for klass in self._model._allKlassesInOrder:
wr('insert into _MKClassIds (id, name) values ')
! wr('\t(%s, %r);\n' % (klass.id(), klass.name()))
wr('\n')
--- 326,330 ----
for klass in self._model._allKlassesInOrder:
wr('insert into _MKClassIds (id, name) values ')
! wr("\t(%s, '%s');\n" % (klass.id(), klass.name()))
wr('\n')
***************
*** 588,592 ****
# add spaces before and after, to prevent
# syntax error if value begins or ends with "
! value = eval('""" '+str(value)+' """')
value = repr(value[1:-1]) # trim off the spaces
value = value.replace('\\011', '\\t')
--- 588,592 ----
# add spaces before and after, to prevent
# syntax error if value begins or ends with "
! value = eval('""" '+str(value)+' """')
value = repr(value[1:-1]) # trim off the spaces
value = value.replace('\\011', '\\t')
***************
*** 647,651 ****
class PrimaryKey:
'''
! This class is not a 'standard' attribute, but just a helper class for the
writeInsertSamplesSQLForLines method, in case the samples.csv file contains
a primary key column (i.e. the serial numbers are specified explicitly).
--- 647,651 ----
class PrimaryKey:
'''
! This class is not a 'standard' attribute, but just a helper class for the
writeInsertSamplesSQLForLines method, in case the samples.csv file contains
a primary key column (i.e. the serial numbers are specified explicitly).
|