Re: [Modeling-users] different models in same package
Status: Abandoned
Brought to you by:
sbigaret
|
From: Sebastien B. <sbi...@us...> - 2003-12-05 10:12:34
|
Hi Mario,
My best bet is that the second model is not loaded at all. Keep in
mind that the model is loaded as soon as the package itself is accessed
--ie. when the package's __init__.py is "traversed". Thus it's no
surprise that those two statements have the very same effect:
> >>> from packone.EntInOne import EntInOne
> >>> from packone.EntInTwo import EntInTwo
What happens here is probably that, since you generated the package w/
the 1st model, the package's __init__.py only loads the 1st model. When
you generated the code for the second model *in the same package*,
__init__.py already exists so it's not overwritten, nor it is changed.
The relevant lines in __init__.py are:
model=3DModel.searchModel("pymone", mydir, verbose=3D0)
if not model:
import warnings
warnings.warn("Couldn't load model pymone")
else:
ModelSet.defaultModelSet().addModel(model)
they should probably be changed into something like:
pymone=3DModel.searchModel("pymone", mydir, verbose=3D0)
pymtwo=3DModel.searchModel("pymtwo", mydir, verbose=3D0)
if not pymone or not pymtwo:
import warnings
warnings.warn("Couldn't load model(s) pymone and/or pymtwo")
else:
ModelSet.defaultModelSet().addModel(pymone)
ModelSet.defaultModelSet().addModel(pymtwo)
HTH, cheers,
-- S=E9bastien.
Mario Ruggier <ma...@ru...> writes:
> Hi,
>=20
> I have two models that I am setting to be in the same
> package, so I have something like:
>=20
> model =3D Model('pymone', packageName=3D'packone',
> connDict=3D{'database':'db_pymone.db'})
> model =3D Model('pymtwo', packageName=3D'packone',
> connDict=3D{'database':'db_pymtwo.db'})
>=20
> in the respective pymodel files. All entity names are distinct
> across both models.
>=20
> The code generation into the same package, and the generation of
> the two db's is fine. However, when I import entities form the second
> model, what seems to happen is that the first model "becomes known"
> but the entity (as it is in the other model) returns None... to clarify:
>=20
> % python
> [GCC Apple cpp-precomp 6.14] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from packone.EntInOne import EntInOne
> >>> from Modeling.ModelSet import defaultModelSet
> >>> ms =3D defaultModelSet()
> >>> ms.modelsNames()
> ['pymone']
> >>> ms.entityNamed('EntInOne')
> <Modeling.Entity.Entity instance at 0x7d3140>
> >>> from packone.EntInTwo import EntInTwo
> >>> ms.modelsNames()
> ['pymone']
> >>> ms.entityNamed('EntInTwo')
> >>> ^D
>=20
> if I only import an entity form the second model, the same thing happens:
>=20
> % python
> [GCC Apple cpp-precomp 6.14] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from packone.EntInTwo import EntInTwo
> >>> from Modeling.ModelSet import defaultModelSet
> >>> ms =3D defaultModelSet()
> >>> ms.modelsNames()
> ['pymone']
> >>> ms.entityNamed('EntInTwo')
> >>> ^D
>=20
> Am I abusing something here?
> Let me know if I should put in a report.
>=20
> Cheers, mario
|