|
From: <de...@us...> - 2003-12-18 00:54:26
|
Update of /cvsroot/pymerase/pymerase/pymerase/output
In directory sc8-pr-cvs1:/tmp/cvs-serv28619
Modified Files:
CreateDBAPI.py
Log Message:
Removed the search and replace on files template system and replaced
it with an interesting %(substitution)s template system (Located in
pymerase/util/Template
This should make installation easier as now everything should be
valid python code so compileall.py should be less grumpy with pymerase.
Index: CreateDBAPI.py
===================================================================
RCS file: /cvsroot/pymerase/pymerase/pymerase/output/CreateDBAPI.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** CreateDBAPI.py 4 Dec 2003 02:52:41 -0000 1.32
--- CreateDBAPI.py 18 Dec 2003 00:54:23 -0000 1.33
***************
*** 44,49 ****
--- 44,51 ----
import types
import shutil
+ from pymerase.util.Template import Template
from pymerase.util.output import *
from pymerase.util.SortMetaInfo import forwardDeclarationSort
+ from pymerase.util.Template import Template
from pymerase.output.dbAPI import fkeyTypes
***************
*** 109,113 ****
"""Create the top of the PythonAPI file
"""
-
header = []
# FIXME: do I really need to make the modules executable?
--- 111,114 ----
***************
*** 380,394 ****
return packageInformation
! def parsePackageInformation(packageInformation):
! def createImports(packageInformation):
module_list = []
! for moduleName, modulePath in packageInformation:
module_list += ["import %s" % (modulePath)]
return string.join(module_list, os.linesep)
! def createModuleToClassList(packageInformation):
module_list = ""
! for moduleName, packagePath in packageInformation:
if type(packagePath) == types.ListType:
modulePath = packagePath
--- 381,399 ----
return packageInformation
! class PackageTemplate(Template):
! def __init__(self, packageInformation):
! Template.__init__(self)
! self.packageInformation = packageInformation
!
! def import_modules(self):
module_list = []
! for moduleName, modulePath in self.packageInformation:
module_list += ["import %s" % (modulePath)]
return string.join(module_list, os.linesep)
! def classes_list(self):
module_list = ""
! for moduleName, packagePath in self.packageInformation:
if type(packagePath) == types.ListType:
modulePath = packagePath
***************
*** 400,418 ****
return '['+module_list+']'
! def createModulesList(packageInformation):
"""Return list of modules, useful for reloading when reinitializing
"""
module_list = []
! for moduleName, modulePath in packageInformation:
module_list += ["%s" % (modulePath)]
return string.join(module_list, ", ")
- package_macros = {}
-
- package_macros['IMPORT_MODULES'] = createImports(packageInformation)
- package_macros['CLASSES_LIST'] = createModuleToClassList(packageInformation)
- package_macros['MODULES_LIST'] = createModulesList(packageInformation)
-
- return package_macros
def writeTemplateFile(package_macros, source_filename, destination_filename):
--- 405,416 ----
return '['+module_list+']'
! def modules_list(self):
"""Return list of modules, useful for reloading when reinitializing
"""
module_list = []
! for moduleName, modulePath in self.packageInformation:
module_list += ["%s" % (modulePath)]
return string.join(module_list, ", ")
def writeTemplateFile(package_macros, source_filename, destination_filename):
***************
*** 434,467 ****
source_file.close()
destination_file.close()
!
def writePackage(destination, package_information):
# write the package definition
! if 1:
! import pymerase.output.dbAPI
! module_pathname = pymerase.output.dbAPI.__path__[0]
! module_path = module_pathname
! else:
! # this code fragment was used when I was looking for
! # a way to avoid the apparent instability of package.__path__
! # however that may have been a mistake
! # and this doesn't work in jython
! import inspect
! module_pathname = inspect.getabsfile(writePackage)
! module_path, module_filename = os.path.split(module_pathname)
! module_path = os.path.join(module_path, "dbAPI")
warn("module_pathname: %s" % (module_pathname), DebugWarning)
# parse package information
! package_macros = parsePackageInformation(package_information)
! # get module_path
! # FIXME: this is for the better segmented version
! files_to_copy = [('dbAPI.pyt', 'dbAPI.py'),
! ('init.pyt', '__init__.py'),
('../../util/bool.py', 'bool.py'),
! ('fkeyTypes.pyt', 'fkeyTypes.py')]
! # files_to_copy = [('dbAPI.py', '__init__.py'),
! # ('fkeyTypes.py', 'fkeyTypes.py')]
# Get filenames
for source_filename, destination_filename in files_to_copy:
--- 432,476 ----
source_file.close()
destination_file.close()
!
! def writeInit(package_template, destination_pathname):
! init = ["import os"]
! init += ["import sys"]
! init += ["import types"]
! init += ["import pgdb as db_api"]
! init += ["from dbAPI import Functor"]
! init += ["from dbAPI import reloadModuleList"]
! init += ["from dbAPI import DBSessionImpl"]
! init += [""]
! init += ["%(import_modules())s"]
! init += [""]
! init += ["moduleReload = Functor(reloadModuleList, (%(modules_list())s))"]
! init += [""]
! init += ["class DBSession(DBSessionImpl):"]
! init += [" def __init__(self, dsn=None, database=None, user=None, password=None):"]
! init += [" classes_to_load = %(classes_list())s"]
! init += [""]
! init += [" DBSessionImpl.__init__(self, dsn, database, user, password)"]
! init += [" self.loadClasses(classes_to_load)"]
! init += [" self.connect()"]
!
! package_template.writeFile(init, destination_pathname)
!
def writePackage(destination, package_information):
# write the package definition
! import pymerase.output.dbAPI
! module_pathname = pymerase.output.dbAPI.__path__[0]
! module_path = module_pathname
warn("module_pathname: %s" % (module_pathname), DebugWarning)
# parse package information
! package_template = PackageTemplate(package_information)
! writeInit(package_template, os.path.join(destination, "__init__.py"))
!
! files_to_copy = [('dbAPI.py', 'dbAPI.py'),
('../../util/bool.py', 'bool.py'),
! ('fkeyTypes.py', 'fkeyTypes.py')]
!
# Get filenames
for source_filename, destination_filename in files_to_copy:
***************
*** 469,473 ****
destination_pathname = os.path.join(destination, destination_filename)
! writeTemplateFile(package_macros, source_pathname, destination_pathname)
# Create dummy init
--- 478,482 ----
destination_pathname = os.path.join(destination, destination_filename)
! shutil.copy(source_pathname, destination_pathname)
# Create dummy init
|