Package Modeling :: Package ModelMasons :: Module ModelMason :: Class ModelMason
[show private | hide private]
[frames | no frames]

Class ModelMason

Known Subclasses:
CMFModelMason, PyModelMason

This class should be the base class for every masons.

When subclassing this class, you should take care of:

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
  __init__(self, model, rootPath, concreteBuilder, bricksDir, verbose_mode, fake_mode)
Initializes the ModelMason so that the built files are based on the supplied model.
  build(self)
Build the product ; override it to match your need.
  build_package(self)
Creates all the necessary directories for the package, which can be something like A.B.C.MyPackage.
  copyFile(self, templateFilename, destinationFilename, overwrite)
Copy the template file to the destination file, unchanged.
  createEmptyFile(self, filename, overwrite)
Create the empty file 'filename' ; the filename is a relative path (relative to 'self.productBaseDirectory()')
  createFileFromTemplate(self, template, destFile, namespace, overwrite)
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.
  fullPathForBrick(self, aBrick)
Returns the full path for a given brick's filename.
  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.
  tmpl_namespace(self)
This method returns a dictionary used by templates to search for specific values.

Method Details

__init__(self, model, rootPath, concreteBuilder, bricksDir, verbose_mode=0, fake_mode=0)
(Constructor)

Initializes the ModelMason so that the built files are based on the supplied model.

Parameters:

model -- the model from which the generated python package should be
generated
rootPath -- path of a directory where the corresponding package should
be dropped

concreteBuilder -- the module containing the concrete builder

bricksDir -- path for the directory containing the templates, relative
to the path where the module of 'concreteBuilder' is stored
verbose_mode -- whether logging is activated or not, see log(). When
true, the building process logs some informations in sys.stderr while generating the files
fake_mode -- if true, do not create or change any file, just report what
would be done

Subclasses may decide to supply a default value for the product's base directory when parameter 'rootPath' is not supplied.

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:

template -- a Cheetah.Template object

namespace -- the template will use that namespace. If ommitted, it
defaults to self.tmpl_namespace()

destFile -- the destination file path, relative to productBaseDirectory

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:

template -- a Cheetah.Template object

namespace -- the template will use that namespace. If ommitted, it
defaults to self.tmpl_namespace()

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().


Generated by Epydoc 2.1 on Sat Mar 4 13:36:21 2006 http://epydoc.sf.net