Package Modeling :: Module Model
[show private | hide private]
[frames | no frames]

Module Modeling.Model

... describe me please I feel alone...

$Id: Model.py,v 1.18 2004/11/30 17:07:37 sbigaret Exp $


Classes
Model Describes a model

Exceptions
InvalidNameException ...
ModelError ...

Function Summary
  loadModel(path)
Load a model stored in the file path.
  loadXMLModel(xml_content)
Loads an xml-model and returns the corresponding Model.
  searchModel(modelName, path, verbose)
Searches for the model named modelName by trying loadModel() with the following paths: pymodel_<modelName>.py, model_<modelName>.py and model_<modelName>.xml in the current directory and the MDL/ directory.
  updateModelWithCFG(model, cfg_path)
Updates the model's connection dictionary and adaptorName with the values in file 'cfg_path'.
  _loadModel(path)
Note: this method does NOT call updateModelWithCFG()

Function Details

loadModel(path)

Load a model stored in the file path. The lookup procedure is:

  • if path ends with .py, we assume it is a python module. This module is imported and the following attributes are searched within it, in that order:

    1. model (either an attribute or a function): if found, the method determines whether this is a Model.Model or a PyModel.Model. If the PyModel has not been built yet, it is build() here.
    2. pymodel (either an attribute or a function): if found, we assume this is an instance of PyModel.Model and we return its 'component' attribute. If the PyModel has not been built yet, it is build() here.
    3. model_src (id.): if found, we assume this is a string and the returned model is built from that xml stream with loadXMLModel()
  • if path ends with .xml, we assume this is a xml-file and we return the model build with loadXMLModel()

Note: this method calls updateModelWithCFG() on the model before returning it. If you want to have the non-updated model, use _loadModel instead.

Parameters:
path - the path of the file where the model is stored
Returns:
the loaded Modeling.Model.Model instance
Raises:
ValueError - if file 'path' cannot be handled, or IOError or ImportError if the files does no exists, has errors, etc.

loadXMLModel(xml_content)

Loads an xml-model and returns the corresponding Model.
Parameters:
xml_content - a string containing the whole xml stream. If the xml is stored in a file, it is suggested that the file is opened in binary mode (for example, loadXMLModel(open(file_path, 'rb').read()))

searchModel(modelName, path=None, verbose=0)

Searches for the model named modelName by trying loadModel() with the following paths: pymodel_<modelName>.py, model_<modelName>.py and model_<modelName>.xml in the current directory and the MDL/ directory.
Returns:
the model, or None if it cannot be found/loaded

updateModelWithCFG(model, cfg_path=None)

Updates the model's connection dictionary and adaptorName with the values in file 'cfg_path'. If cfg_path is omitted or None, the value stored in the environment variable MDL_DB_CONNECTIONS_CFG is used instead.

A sample configuration file is like:

[DEFAULT]
host: localhost

[ModelName_1]
user: user_1
password: pwd_1

[ModelName_2]
adaptor: MySQL
user: user_2
password: pwd_2

The special field 'adaptor', if present, changes the adaptorName of the model.

Raises IOError if file 'cfg_path' cannot be found.

See also: ModelSet.addModel()

Parameters:
model - the model whose conn.dict. should be updated
cfg_path - the full path to the configuration file, or if omitted or None, defaults to the value stored in the env. variable MDL_DB_CONNECTIONS_CFG

_loadModel(path)

Note: this method does NOT call updateModelWithCFG()
Returns:
a tuple (model, model_type), where model is the model itself, and model_type a string being either "xmlmodel" or "pymodel" indicating whether the model was found in a xml stream or in a PyModel.

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