[Modeling-users] New feature: PyModel
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-07-09 11:55:57
|
Hi all, I'm glad to announce that the cvs brch used to develop the PyModel (model expressed in plain python, rather than in an explicit xml file) is now explicitly closed; it has been integrated to the main trunk yesterday. It will included in the next release. PyModels are an *alternative* for xml models; both directly map to Modeling.Model instances when loaded at runtime. Both formats are and will be supported in the future. Many thanks to Mario who kept hassling me about a nicer and handier model representation than xml ;) and to all those who discussed the new feature. Since it will probably take some time before the documentation initiated by Mario is finalized, here is a overview of what has been done, and what still needs to be done. - The three scripts mdl_generate_python_code.py, mdl_generate_DB_schema.py and mdl_validate_model.py have been adapted to take either an xmlmodel or a pymodel as their argument. - Examples PyModels are integrated into testPackages, see Modeling/tests/testPackages/AuthorBooks/pymodel_AuthorBooks.py and Modeling/tests/testPackages/StoreEmployees/pymodel_StoreEmployees.py - Reminder: you can find more informations by referring to the thread where we discussed the PyModels: https://sourceforge.net/mailarchive/forum.php?thread_id=3D1702463&forum_id= =3D10674 https://sourceforge.net/mailarchive/forum.php?thread_id=3D1703927&forum_id= =3D10674 https://sourceforge.net/mailarchive/forum.php?thread_id=3D1755270&forum_id= =3D10674 - There is no script converting xml models to pymodels yet. Hence, the ZModeler still only dumps xml models. This will be integrated in the next release, probably mdl_convert_model.py Backward incompatibility: none intended, and none observed for the time being. Existing projects will continue to work as expected. Loading a model --------------- If you try the cvs version, you'll probably notice that method ModelSet.loadModel() (used in generated __init__.py, probably in your package as well) has been deprecated. It has been moved to module Model.loadModel(). The new scheme for loading a model (supporting PyModels as well as xml models), as included in __init__.py for generated packages, is shorter than the previous one: ------------------------------------------------------------------------ # Load the model MODEL_NAME=3D'your_model_name' from Modeling import ModelSet, Model if ModelSet.defaultModelSet().modelNamed(MODEL_NAME) is None: import os mydir =3D os.path.abspath(os.path.dirname(__file__)) model=3DModel.searchModel(MODEL_NAME, mydir, verbose=3D0) if not model: import warnings warnings.warn("Couldn't load model %s'%MODEL_NAME) else: ModelSet.defaultModelSet().addModel(model) ------------------------------------------------------------------------ (see docstring for Model.searchModel() for details) Known bugs: ----------- Only one for the moment being: if you need to load more than one PyModel at runtime, you'll probably encounter strange behaviour; this is due to defaults leaking from one model to the other one. A quick fix is to add: 'import PyModel; reload(PyModel)' before loading the pymodel. It'd be great if some of you could spend some time to test it and report. For those who do not want to use pserver-based cvs (which too often ends up with EOF received from sf), a cvs snapshot can be downloaded at: http://modeling.sourceforge.net/download/ModelingCore-0.9-pre-9.PyModel.tar= .gz And feel free to ask for more informations! Regards, -- S=E9bastien. |