From e45a0996988b7b1e31e1ef2a5d1b736187cc646a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 3 Dec 2016 12:50:36 +0100 Subject: [PATCH] extend generation framework to set Python class name --- src/Tools/generateBase/generateDS.py | 3 + .../generateBase/generateMetaModel_Module.xsd | 2 + .../generateBase/generateModel_Module.py | 84 ++++++++++--------- .../templateClassPyExport.py | 4 + 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/Tools/generateBase/generateDS.py b/src/Tools/generateBase/generateDS.py index bf6a4ff10..e339ecf75 100644 --- a/src/Tools/generateBase/generateDS.py +++ b/src/Tools/generateBase/generateDS.py @@ -3215,6 +3215,9 @@ Options: --root-element="XXX" Assume XXX is root element of instance docs. Default is first element defined in schema. --super="XXX" Super module name in subclass module. Default="???" + +Example: +python generateDS.py -o generateModel_Module.py generateMetaModel_Module.xsd """ def usage(): diff --git a/src/Tools/generateBase/generateMetaModel_Module.xsd b/src/Tools/generateBase/generateMetaModel_Module.xsd index dae8f40e1..b55b9ffc7 100644 --- a/src/Tools/generateBase/generateMetaModel_Module.xsd +++ b/src/Tools/generateBase/generateMetaModel_Module.xsd @@ -55,6 +55,7 @@ + @@ -67,6 +68,7 @@ + diff --git a/src/Tools/generateBase/generateModel_Module.py b/src/Tools/generateBase/generateModel_Module.py index 691776ef3..1141cac25 100644 --- a/src/Tools/generateBase/generateModel_Module.py +++ b/src/Tools/generateBase/generateModel_Module.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# Generated Thu Jul 22 14:11:34 2010 by generateDS.py. +# Generated Sat Dec 03 11:48:45 2016 by generateDS.py. # import sys @@ -216,14 +216,16 @@ class GenerateModel: class PythonExport: subclass = None - def __init__(self, FatherNamespace='', RichCompare=0, Name='', Reference=0, FatherInclude='', Father='', Namespace='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations='', Initialization=0): + def __init__(self, FatherNamespace='', RichCompare=0, Name='', Reference=0, FatherInclude='', Namespace='', Initialization=0, Father='', PythonName='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations=''): self.FatherNamespace = FatherNamespace self.RichCompare = RichCompare self.Name = Name self.Reference = Reference self.FatherInclude = FatherInclude - self.Father = Father self.Namespace = Namespace + self.Initialization = Initialization + self.Father = Father + self.PythonName = PythonName self.Twin = Twin self.Constructor = Constructor self.TwinPointer = TwinPointer @@ -231,7 +233,6 @@ class PythonExport: self.NumberProtocol = NumberProtocol self.Delete = Delete self.Documentation = Documentation - self.Initialization = Initialization if Methode is None: self.Methode = [] else: @@ -249,8 +250,6 @@ class PythonExport: else: return PythonExport(*args_, **kwargs_) factory = staticmethod(factory) - def getInitialization(self): return self.Initialization - def setInitialization(self, Initialization): self.Initialization = Initialization def getDocumentation(self): return self.Documentation def setDocumentation(self, Documentation): self.Documentation = Documentation def getMethode(self): return self.Methode @@ -277,10 +276,14 @@ class PythonExport: def setReference(self, Reference): self.Reference = Reference def getFatherinclude(self): return self.FatherInclude def setFatherinclude(self, FatherInclude): self.FatherInclude = FatherInclude - def getFather(self): return self.Father - def setFather(self, Father): self.Father = Father def getNamespace(self): return self.Namespace def setNamespace(self, Namespace): self.Namespace = Namespace + def getInitialization(self): return self.Initialization + def setInitialization(self, Initialization): self.Initialization = Initialization + def getFather(self): return self.Father + def setFather(self, Father): self.Father = Father + def getPythonname(self): return self.PythonName + def setPythonname(self, PythonName): self.PythonName = PythonName def getTwin(self): return self.Twin def setTwin(self, Twin): self.Twin = Twin def getConstructor(self): return self.Constructor @@ -309,13 +312,15 @@ class PythonExport: if self.getReference() is not None: outfile.write(' Reference="%s"' % (self.getReference(), )) outfile.write(' FatherInclude="%s"' % (self.getFatherinclude(), )) - outfile.write(' Father="%s"' % (self.getFather(), )) outfile.write(' Namespace="%s"' % (self.getNamespace(), )) + if self.getInitialization() is not None: + outfile.write(' Initialization="%s"' % (self.getInitialization(), )) + outfile.write(' Father="%s"' % (self.getFather(), )) + if self.getPythonname() is not None: + outfile.write(' PythonName="%s"' % (self.getPythonname(), )) outfile.write(' Twin="%s"' % (self.getTwin(), )) if self.getConstructor() is not None: outfile.write(' Constructor="%s"' % (self.getConstructor(), )) - if self.getInitialization() is not None: - outfile.write(' Initialization="%s"' % (self.getInitialization(), )) outfile.write(' TwinPointer="%s"' % (self.getTwinpointer(), )) outfile.write(' Include="%s"' % (self.getInclude(), )) if self.getNumberprotocol() is not None: @@ -351,15 +356,18 @@ class PythonExport: showIndent(outfile, level) outfile.write('FatherInclude = "%s",\n' % (self.getFatherinclude(),)) showIndent(outfile, level) + outfile.write('Namespace = "%s",\n' % (self.getNamespace(),)) + showIndent(outfile, level) + outfile.write('Initialization = "%s",\n' % (self.getInitialization(),)) + showIndent(outfile, level) outfile.write('Father = "%s",\n' % (self.getFather(),)) showIndent(outfile, level) - outfile.write('Namespace = "%s",\n' % (self.getNamespace(),)) + outfile.write('PythonName = "%s",\n' % (self.getPythonname(),)) showIndent(outfile, level) outfile.write('Twin = "%s",\n' % (self.getTwin(),)) showIndent(outfile, level) outfile.write('Constructor = "%s",\n' % (self.getConstructor(),)) showIndent(outfile, level) - outfile.write('Initialization = "%s",\n' % (self.getInitialization(),)) outfile.write('TwinPointer = "%s",\n' % (self.getTwinpointer(),)) showIndent(outfile, level) outfile.write('Include = "%s",\n' % (self.getInclude(),)) @@ -435,10 +443,19 @@ class PythonExport: raise ValueError('Bad boolean attribute (Reference)') if attrs.get('FatherInclude'): self.FatherInclude = attrs.get('FatherInclude').value - if attrs.get('Father'): - self.Father = attrs.get('Father').value if attrs.get('Namespace'): self.Namespace = attrs.get('Namespace').value + if attrs.get('Initialization'): + if attrs.get('Initialization').value in ('true', '1'): + self.Initialization = 1 + elif attrs.get('Initialization').value in ('false', '0'): + self.Initialization = 0 + else: + raise ValueError('Bad boolean attribute (Initialization)') + if attrs.get('Father'): + self.Father = attrs.get('Father').value + if attrs.get('PythonName'): + self.PythonName = attrs.get('PythonName').value if attrs.get('Twin'): self.Twin = attrs.get('Twin').value if attrs.get('Constructor'): @@ -448,13 +465,6 @@ class PythonExport: self.Constructor = 0 else: raise ValueError('Bad boolean attribute (Constructor)') - if attrs.get('Initialization'): - if attrs.get('Initialization').value in ('true', '1'): - self.Initialization = 1 - elif attrs.get('Initialization').value in ('false', '0'): - self.Initialization = 0 - else: - raise ValueError('Bad boolean attribute (Initialization)') if attrs.get('TwinPointer'): self.TwinPointer = attrs.get('TwinPointer').value if attrs.get('Include'): @@ -506,11 +516,6 @@ class PythonExport: for text__content_ in child_.childNodes: ClassDeclarations_ += text__content_.nodeValue self.ClassDeclarations = ClassDeclarations_ - elif child_.nodeType == Node.ELEMENT_NODE and \ - nodeName_ == 'Initialization': - obj_ = Documentation.factory() - obj_.build(child_) - self.setDocumentation(obj_) # end class PythonExport @@ -1828,12 +1833,23 @@ class SaxGeneratemodelHandler(handler.ContentHandler): val = attrs.get('FatherInclude', None) if val is not None: obj.setFatherinclude(val) - val = attrs.get('Father', None) - if val is not None: - obj.setFather(val) val = attrs.get('Namespace', None) if val is not None: obj.setNamespace(val) + val = attrs.get('Initialization', None) + if val is not None: + if val in ('true', '1'): + obj.setInitialization(1) + elif val in ('false', '0'): + obj.setInitialization(0) + else: + self.reportError('"Initialization" attribute must be boolean ("true", "1", "false", "0")') + val = attrs.get('Father', None) + if val is not None: + obj.setFather(val) + val = attrs.get('PythonName', None) + if val is not None: + obj.setPythonname(val) val = attrs.get('Twin', None) if val is not None: obj.setTwin(val) @@ -1845,14 +1861,6 @@ class SaxGeneratemodelHandler(handler.ContentHandler): obj.setConstructor(0) else: self.reportError('"Constructor" attribute must be boolean ("true", "1", "false", "0")') - val = attrs.get('Initialization', None) - if val is not None: - if val in ('true', '1'): - obj.setInitialization(1) - elif val in ('false', '0'): - obj.setInitialization(0) - else: - self.reportError('"Initialization" attribute must be boolean ("true", "1", "false", "0")') val = attrs.get('TwinPointer', None) if val is not None: obj.setTwinpointer(val) diff --git a/src/Tools/generateTemplates/templateClassPyExport.py b/src/Tools/generateTemplates/templateClassPyExport.py index f15fe8f8c..de93a58f5 100644 --- a/src/Tools/generateTemplates/templateClassPyExport.py +++ b/src/Tools/generateTemplates/templateClassPyExport.py @@ -247,7 +247,11 @@ using namespace @self.export.Namespace@; PyTypeObject @self.export.Name@::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ ++ if (self.export.PythonName): + "@self.export.PythonName@", /*tp_name*/ += else: "@self.export.Namespace@.@self.export.Twin@", /*tp_name*/ +- sizeof(@self.export.Name@), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */