Update of /cvsroot/modeling/ProjectModeling/Modeling/ModelMasons/Python_bricks
In directory sc8-pr-cvs1:/tmp/cvs-serv7471/ProjectModeling/Modeling/ModelMasons/Python_bricks
Modified Files:
init.tmpl
Log Message:
Merged branch brch-0_9pre7-1-PyModel. Introducing: ability to express models
in plain python rather than in xml files.
See CHANGES for details.
Index: init.tmpl
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/ModelMasons/Python_bricks/init.tmpl,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** init.tmpl 26 May 2003 15:44:48 -0000 1.6
--- init.tmpl 7 Jul 2003 14:57:14 -0000 1.7
***************
*** 1,71 ****
## This template will build the __init__.py file
- #import time
- # Generated by mdl_generate_python_code.py / time.strftime("%Y/%m/%d %H:%M")
#set $model_name = str($model().name())
# Load the model
! #---------------------------------------
! def loadModel():
! """Load model from either the pickled model created by mdl_compile_model.py
! or from the string stored in model_$(model_name).model_src
! The module containing the pickled model is usually generated with the
! script mdl_compile_model.py
! Simply returns if a model named "$model_name" has already been loaded
! """
! from Modeling import ModelSet
! import os, warnings, cStringIO, traceback
! if ModelSet.defaultModelSet().modelNamed("$(model_name)") is not None:
! return
! try:
! #if $base_dir:
! from $(base_dir).model_$(model_name)_pickle import model_pickle
! #else
! from model_$(model_name)_pickle import model_pickle
! #end if
! import cPickle
! m=cPickle.loads(model_pickle)
! ModelSet.defaultModelSet().addModel(m)
! model=ModelSet.defaultModelSet().modelNamed("$(model_name)")
! except:
! exc=cStringIO.StringIO()
! traceback.print_exc(file=exc)
! warnings.warn("Couldn't load model from pickle'\n"\
! "Reason:\n%s"%exc.getvalue())
! del exc
else:
! return
!
! try:
! #if $base_dir:
! from $(base_dir).model_$(model_name) import model_src
! #else
! from model_$(model_name) import model_src
! #end if
! ModelSet.defaultModelSet().addModelFromXML({'string': model_src})
! model=ModelSet.defaultModelSet().modelNamed("$(model_name)")
! except:
! exc=cStringIO.StringIO()
! traceback.print_exc(file=exc)
! warnings.warn("Couldn't load model 'model_$(model_name).xml'\nReason:\n%s"%exc.getvalue())
! del exc
!
! # Or, alternatively: use the xml file (ok for dev. mode, not for install w/
! # distutils)
! #
! # try:
! # from os import getcwd, path
! # mydir = os.path.abspath(os.path.dirname(__file__))
! # xmlmodelPath=path.join(mydir,'model_$(model_name).xml')
! # ModelSet.defaultModelSet().addModelFromXML({'file': xmlmodelPath})
! # model=ModelSet.defaultModelSet().modelNamed('$(model_name)')
! # except:
! # exc=cStringIO.StringIO()
! # traceback.print_exc(file=exc)
! # warnings.warn("Couldn't load model 'model_$(model_name).xml'\nReason:\n%s"%exc.getvalue())
! # del exc
! #
! # del os, warnings, StringIO, traceback
! #---------------------------------------
! loadModel()
--- 1,16 ----
## This template will build the __init__.py file
#set $model_name = str($model().name())
# Load the model
! from Modeling import ModelSet, Model
! if ModelSet.defaultModelSet().modelNamed("$(model_name)") is None:
! import os
! mydir = os.path.abspath(os.path.dirname(__file__))
! model=Model.searchModel('$(model_name)', mydir, verbose=0)
! if not model:
! import warnings
! warnings.warn("Couldn't load model '$(model_name)'")
else:
! ModelSet.defaultModelSet().addModel(model)
|