Re: [Modeling-users] pymodel implementation [was: install tests on 0.9pre11]
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-07-31 17:43:35
|
Mario Ruggier <ma...@ru...> wrote: > Just looking into the PyModel implementation, and get the following: >=20 > % mdl_validate_model.py pymodel_StoreEmployees.py > Serious: couldn't load the model > exceptions.IndentationError > expected an indented block (line 231) > File "/usr/bin/mdl_validate_model.py", line 118, in main > from Modeling import Model >=20 > This from a CVS installation today, with the only difference being > the patch applied above (and with all the tests in test/README > passing OK, except for teh one noted exception earlier). I do not get this error at all and do not see why it happens. I do not even understand to what "(line 231)" applies to. Any hint on your side? > Other quick questions: >=20 > - in the example pymodel_StoreEmployees.py, what is the > component being returned (as in pymodel().component) ? This is described in the doc. string of Model.loadModel(), this is the function that searches for the model. http://modeling.sf.net/API/Modeling-API/public/Modeling.Model-module.html#l= oadModel But it is a little bit out of sync, i'll change it: in fact, when it finds an attribute 'model' in a python module (item 1. in the docstring) it checks whether this is a PyModel or not. > - Why did you opt for requiring a model.build() at the end of a pymodel? > Could this not have been handled automatically from within Model? You're absolutely right, loadModel() can build() it automatically. Enclosed is a patch that enables this --it will be in next version. I also include here a simpler version of pymodel_StoreEmployees.py Thanks for all these comments, that makes things cleaner I think. =20=20 -- S=E9bastien. ------------------------------------------------------------------------ --- Model.py 24 Jul 2003 11:10:53 -0000 1.10 +++ Model.py 31 Jul 2003 16:55:06 -0000 @@ -165,6 +165,7 @@ model=3Dmodel() import PyModel if isinstance(model, PyModel.Model): + model.build() model=3Dmodel.component updateModelWithCFG(model) return model @@ -173,6 +174,7 @@ pymodel=3Dmodule.pymodel if callable(pymodel): pymodel=3Dpymodel() + pymodel.build() updateModelWithCFG(pymodel.component) return pymodel.component ------------------------------------------------------------------------ #! /usr/bin/env python ''' A sample Pythonic OO-RDB Model=20 (re-expressing testPackages/StoreEmployees/model_StoreEmployees.xml) -- A PyModel must define a global variable called 'model', that is of type Mod= el ''' from Modeling.PyModel import * ## # Set preferred defaults for this model (when different from=20 # standard defaults, or if we want to make things explicit) AFloat.defaults['precision'] =3D 10 AFloat.defaults['scale'] =3D 10 AString.defaults['width'] =3D 30 Association.defaults['delete']=3D['nullify', 'nullify'] Entity.defaults['properties'] =3D [ APrimaryKey('id', isClassProperty=3D0, isRequired=3D1, doc=3D'Primary key= !') ] ## _connDict =3D {'database': 'STORE_EMPLOYEES'} model =3D Model('StoreEmployees',adaptorName=3D'Postgresql', connDict=3D_connDict) model.doc =3D ' ... ' model.version=3D'0.1' model.entities =3D [ # Entity('Store', properties=3D[ AString('corporateName', isRequired=3D1), ], ), Entity('Employee', properties=3D[ AString('lastName',isRequired=3D1,usedForLocking=3D= 1, width=3D20), AString('firstName', isRequired=3D1, width=3D50, usedForLocking=3D1), ] ), Entity('SalesClerk', parent=3D'Employee', properties=3D[ AString('storeArea', width=3D20) ] ), Entity('Executive', parent=3D'Employee', properties=3D[ AString('officeLocation', width=3D5) ] ), Entity('Address', properties=3D[ AString('street', width=3D80),=20 AString('zipCode', width=3D10),=20 AString('town'), ] ), Entity('Mark', properties=3D[ AInteger('month', isRequired=3D1),=20 AInteger('mark', isRequired=3D1), ] ), Entity('Holidays', properties=3D[ ADateTime('startDate', isRequired=3D1),=20 ADateTime('endDate', isRequired=3D1), ] ), ] model.associations=3D[ Association('Mark', 'Executive', relations=3D['executive', 'marks'], delete=3D['nullify', 'cascade'], keys=3D['FK_Executive_id', 'id']), Association('Address', 'Employee', relations=3D['toEmployee', 'toAddresses'], delete=3D['deny', 'cascade'], keys=3D['fkEmployeeId', 'id'], ), Association('Employee', 'Store', relations=3D['toStore', 'employees'], delete=3D['nullify', 'deny'], keys=3D['fkStoreId', 'id']), Association('Holidays', 'Employee', relations=3D[None, 'holidays'], delete=3D[None, 'cascade'], keys=3D['fkEmployeeId', 'id']), ] |