[Modeling-cvs] ProjectModeling/Modeling/ModelMasons PyModelMason.py,1.8.2.1,1.8.2.2
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-05-16 11:04:43
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/ModelMasons In directory sc8-pr-cvs1:/tmp/cvs-serv21096a/ModelMasons Modified Files: Tag: brch-0_9pre6-1-ModelMasons_base_generation_scheme PyModelMason.py Log Message: Added: check that the model is valid for the 'base' generation scheme + fixed: __init__ in MDL/ was not overwritten Index: PyModelMason.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/ModelMasons/PyModelMason.py,v retrieving revision 1.8.2.1 retrieving revision 1.8.2.2 diff -C2 -d -r1.8.2.1 -r1.8.2.2 *** PyModelMason.py 21 Apr 2003 22:53:05 -0000 1.8.2.1 --- PyModelMason.py 16 May 2003 11:04:40 -0000 1.8.2.2 *************** *** 42,45 **** --- 42,100 ---- from Python_bricks import init,init_base,model,base_module,module_base,module_compact,setup_tmpl + class InvalidModelError(Exception): + "Raised by checkModelIsValid()" + pass + + def checkModelIsValid(model, generation_scheme): + """ + Checks that the supplied model is valid for a given python-code generation + scheme: + + - if 'generation_scheme' is 'compact', all models are valid, + + - if 'generation_scheme' is 'base', the model is valid iff a class/entity does + not share the same module than any of its subclasses + + Parameters: + + model -- a instance of Modeling.Model.Model + + generation_scheme -- either 'compact' or 'base' + + Returns: None + + Raises InvalidModelError if the model is invalid. + + Note: this is NOT validation of the model itself (responsability of + Modeling.ModelValidation) + + """ + if generation_scheme=='compact': return + if generation_scheme=='base': + + # Build ordered list of entities + oe=[] + entities=list(model.entities()) + entities_processed=[] + for entity in [e for e in entities if not e.parentEntity()]: + oe.append(entity) + entities_processed.append(entity.name()) + entities.remove(entity) + while entities: + es=[e for e in entities if e.parentEntity().name() in entities_processed] + for entity in es: + entities.remove(entity) + entities_processed.append(entity.name()) + oe.append(entity) + # check every parent against it subentities + for e in oe: + parent_moduleName=e.moduleName() + subs=e.allSubEntities() + for sub in subs: + if sub.moduleName()==parent_moduleName: + raise InvalidModelError, "Model is invalid wrt the 'base' generation scheme: entity '%s' and its subentity '%s' share the same moduleName.\nEither correct this or use the 'compact' generation scheme"%(e.name(), sub.name()) + else: + raise ValueError, "Invalid value for 'generation_scheme' (%s), should be either 'base' or 'compact'"%use_scheme + class PyModelMason(ModelMason): def __init__(self, model, rootPath=None, verbose_mode=0, *************** *** 63,66 **** --- 118,122 ---- if generation_scheme not in ('compact', 'base'): raise ValueError,"Parameter generation_scheme can be either 'compact' or 'base'" + checkModelIsValid(model, generation_scheme) ModelMason.__init__(self, model, rootPath, Modeling.ModelMasons.PyModelMason, 'Python_bricks', *************** *** 144,148 **** self.createFileFromTemplate(init_base.init_base(), os.path.join(self.base_dir,"__init__.py"), ! overwrite=0) create_model_files(self, --- 200,204 ---- self.createFileFromTemplate(init_base.init_base(), os.path.join(self.base_dir,"__init__.py"), ! overwrite=1) create_model_files(self, |