Home | Trees | Index | Help |
|
---|
Package Modeling :: Package ModelMasons :: Module ModelMason :: Class ModelMason |
|
CMFModelMason
,
PyModelMason
This class should be the base class for every masons.
When subclassing this class, you should take care of:
call ModelMason.__init__() if it is overridden
if the subclass needs to change/create sth. on the filesystem, it must check whether 'fake_mode' is set: if it is set, absolutely no changes should be made on the disk.
Methods createEmptyFile(), createFileFromTemplate(), copyFile() and build_package() can be used without this precaution since they already check 'self.fake_mode' before making any changes on the disk.
call log() to record any action relative to the generation (such as the creation of a file). Please note that you should be ready to log these actions even when fake_mode is set. For example, suppose 'file.py' should be generated but not overwritten; if the file does not exist you'd log('Creating file file.py'), and if it exists you'd log('File.py exists, skipping') whether fake_mode is set or not. This makes it possible for the user to see what would happen whene (re)generating the code without actually making the changes.
Following these rules makes it easy to integrate a custom ''mason'' into the script mdl_generate_python_code and the ZModeler.
All subclasses need to override build() and put there the logic which generates the code. You will probably override method tmpl_namespace() as well (see its documentation for details).
You can also refer to PyModelMason for an example of use.
Method Summary | |
---|---|
Initializes the ModelMason so that the built files are based on the supplied model. | |
Build the product ; override it to match your need. | |
Creates all the necessary directories for the package, which can be something like A.B.C.MyPackage. | |
Copy the template file to the destination file, unchanged. | |
Create the empty file 'filename' ; the filename is a relative path (relative to 'self.productBaseDirectory()') | |
Parameters: | |
Returns a list of list of entities, where Entities in the same list share the same 'moduleName' | |
Internally used to make any values in the namespace callable --if a value is an instance or a python object, it is by a lambda function returning the value. | |
Returns the full path for a given brick's filename. | |
Returns the full path for a given generated filename. | |
Logs the msg to stderr if self.verbose_mode is true | |
Initializes a Template object from the supplied templateFile. | |
This method returns a dictionary used by templates to search for specific values. |
Class Variable Summary | |
---|---|
list |
_marker = []
|
Method Details |
---|
__init__(self,
model,
rootPath,
concreteBuilder,
bricksDir,
verbose_mode=0,
fake_mode=0)
|
build(self)Build the product ; override it to match your need. Base implementation does nothing. |
build_package(self)Creates all the necessary directories for the package, which can be something like A.B.C.MyPackage. Creates an empty '__init__.py' in each sub-directories if needed: existing __init__.py are not overwritten. |
copyFile(self, templateFilename, destinationFilename, overwrite=0)Copy the template file to the destination file, unchanged. Both filenames should be relative to, respectively, bricksBaseDirectory and productBaseDirectory. |
createEmptyFile(self, filename, overwrite=0)Create the empty file 'filename' ; the filename is a relative path (relative to 'self.productBaseDirectory()') |
createFileFromTemplate(self, template, destFile, namespace=[], overwrite=0)Parameters:
|
entitiesSet(self)Returns a list of list of entities, where Entities in the same list share the same 'moduleName' |
fix_tmpl_namespace(self, namespace)Internally used to make any values in the namespace callable --if a value is an instance or a python object, it is by a lambda function returning the value. We make this because Cheetah sometimes requires a callable. |
fullPathForBrick(self, aBrick)Returns the full path for a given brick's filename. This is the preferred way for accessing bricks |
fullPathForGeneratedFile(self, filename)Returns the full path for a given generated filename. |
log(self, msg)Logs the msg to stderr if self.verbose_mode is true |
templateObjectForTemplate(self, template, namespace=[])Initializes a Template object from the supplied templateFile. Overrides this to perform any additional initializations for Templates, such as building a namespace for the template. Parameters:
Default implementation simply returns the Template object |
tmpl_namespace(self)This method returns a dictionary used by templates to search for specific values. Default implementation returns: {'model': self.model} Subclasses override this method to provide their own namespace. This namespace is the default one transmitted to the Cheetah template when no specific namespace is passed to method createFileFromTemplate(). |
Class Variable Details |
---|
_marker
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Sat Mar 4 13:36:21 2006 | http://epydoc.sf.net |