Commit 147dff8f authored by De Boissieu Florian's avatar De Boissieu Florian

added options for pre/post constructor and imports

--HG--
branch : settersOptions
parent 839999a2
...@@ -4192,7 +4192,8 @@ def generateCtor(wrt, prefix, element): ...@@ -4192,7 +4192,8 @@ def generateCtor(wrt, prefix, element):
# came from. # came from.
wrt(' self.original_tagname_ = None\n') wrt(' self.original_tagname_ = None\n')
# if AddAttributes: # if AddAttributes:
wrt(" self.troot = get_gs_troot('plots', '%s')\n" % cleanupName(elName)) if PreCtor is not None:
wrt(" %s\n" % PreCtor.format(classname=cleanupName(elName))) # self.troot = get_gs_troot('plots', '%classname')
attrDefs = element.getAttributeDefs() attrDefs = element.getAttributeDefs()
attribNameList=[] attribNameList=[]
for key in element.getAttributeDefsList(): for key in element.getAttributeDefsList():
...@@ -4231,6 +4232,8 @@ def generateCtor(wrt, prefix, element): ...@@ -4231,6 +4232,8 @@ def generateCtor(wrt, prefix, element):
mbrname = name + '_member' mbrname = name + '_member'
else: else:
mbrname = name mbrname = name
if GenerateProperties:
name = '_'+name
attrType = attrDef.getType() attrType = attrDef.getType()
if attrType == DateTimeType: if attrType == DateTimeType:
wrt(" if isinstance(%s, BaseStrType_):\n" % (mbrname, )) wrt(" if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
...@@ -4272,6 +4275,8 @@ def generateCtor(wrt, prefix, element): ...@@ -4272,6 +4275,8 @@ def generateCtor(wrt, prefix, element):
mbrname = name + '_member' mbrname = name + '_member'
else: else:
mbrname = name mbrname = name
if GenerateProperties:
name = '_'+name
_log.debug("Constructor child: %s" % name) _log.debug("Constructor child: %s" % name)
_log.debug("Dump: %s" % child.__dict__) _log.debug("Dump: %s" % child.__dict__)
childType = child.getType() childType = child.getType()
...@@ -4347,9 +4352,9 @@ def generateCtor(wrt, prefix, element): ...@@ -4347,9 +4352,9 @@ def generateCtor(wrt, prefix, element):
wrt(' else:\n') wrt(' else:\n')
wrt(' self.%s = %s\n' % (name, mbrname)) wrt(' self.%s = %s\n' % (name, mbrname))
else: else:
# wrt(' self.%s = %s\n' % (name, mbrname)) wrt(' self.%s = %s\n' % (name, mbrname))
wrt(' self.%s = None\n' % (name)) # wrt(' self.%s = None\n' % (name))
wrt(' self.set%s(%s)\n' % (capName, mbrname)) # wrt(' self.set%s(%s)\n' % (capName, mbrname))
# validate if it is a simple type. Validation shows # validate if it is a simple type. Validation shows
# a warning so no fear that an error would rise. # a warning so no fear that an error would rise.
typeName = child.getSimpleType() typeName = child.getSimpleType()
...@@ -4368,8 +4373,8 @@ def generateCtor(wrt, prefix, element): ...@@ -4368,8 +4373,8 @@ def generateCtor(wrt, prefix, element):
wrt(' self.extensiontype_ = extensiontype_\n') wrt(' self.extensiontype_ = extensiontype_\n')
if element.isMixed(): if element.isMixed():
wrt(MixedCtorInitializers) wrt(MixedCtorInitializers)
if PostSetter is not None: if PostCtor is not None:
wrt(' %s\n' % (PostSetter)) wrt(' %s\n' % (PostCtor))
...@@ -4753,49 +4758,65 @@ def generateGettersAndSetters(wrt, element): ...@@ -4753,49 +4758,65 @@ def generateGettersAndSetters(wrt, element):
name = cleanupName(child.getCleanName()) name = cleanupName(child.getCleanName())
unmappedName = cleanupName(child.getName()) unmappedName = cleanupName(child.getName())
capName = make_gs_name(unmappedName) capName = make_gs_name(unmappedName)
wrt(' def get%s(self): return self.%s\n' % (capName, name)) varname = name
wrt(' def set%s(self, %s):\n' % (capName, name)) if GenerateProperties:
wrt(' self.%s = %s\n' % (name, name)) varname = '_'+varname
wrt(' if %s is not None:\n' % (name)) wrt(' def get%s(self): return self.%s\n' % (capName, varname))
wrt(' def set%s(self, value):\n' % (capName))
wrt(' if value is not None:\n')
if child.getType() == SequenceType: if child.getType() == SequenceType:
wrt(' for %s in self.%s\n' % (name, name)) wrt(' for v in value\n')
wrt(' %s.parent = self\n' % (name)) wrt(' v.parent = self\n')
else: else:
wrt(' self.%s.parent = self\n' % (name)) wrt(' value.parent = self\n')
wrt(' self.%s = value\n' % (varname))
if PostSetter is not None: if PostSetter is not None:
wrt(' if value is not None:\n')
wrt(' %s\n' % (PostSetter)) wrt(' %s\n' % (PostSetter))
if child.getMaxOccurs() > 1: if child.getMaxOccurs() > 1:
wrt(' def add%s(self, value):\n' % (capName)) wrt(' def add%s(self, value):\n' % (capName))
wrt(' value.parent = self\n') wrt(' value.parent = self\n')
wrt(' self.%s.append(value)\n' % (name)) wrt(' self.%s.append(value)\n' % (varname))
if PostSetter is not None: if PostSetter is not None:
wrt(' %s\n' % (PostSetter)) wrt(' %s\n' % (PostSetter))
suffix = make_gs_name('at') suffix = make_gs_name('at')
wrt(' def insert%s%s(self, index, value):\n' % (capName, suffix)) wrt(' def insert%s%s(self, index, value):\n' % (capName, suffix))
wrt(' self.%s.insert(index, value)\n' % (name)) wrt(' self.%s.insert(index, value)\n' % (name))
wrt(' value.parent = self\n') wrt(' value.parent = self\n')
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
wrt(' def replace%s%s(self, index, value):\n' % (capName, suffix)) wrt(' def replace%s%s(self, index, value):\n' % (capName, suffix))
wrt(' value.parent = self\n') wrt(' value.parent = self\n')
wrt(' self.%s[index] = value\n' % (name)) wrt(' self.%s[index] = value\n' % (name))
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
if GenerateProperties: if GenerateProperties:
wrt(' %sProp = property(get%s, set%s)\n' % # wrt(' %sProp = property(get%s, set%s)\n' %
# (unmappedName, capName, capName))
wrt(' %s = property(get%s, set%s)\n' %
(unmappedName, capName, capName)) (unmappedName, capName, capName))
attrDefs = element.getAttributeDefs() attrDefs = element.getAttributeDefs()
for key in element.getAttributeDefsList(): for key in element.getAttributeDefsList():
attrDef = attrDefs[key] attrDef = attrDefs[key]
name = cleanupName(attrDef.getName().replace(':', '_')) name = cleanupName(attrDef.getName().replace(':', '_'))
mappedName = mapName(name) mappedName = mapName(name)
varname = mappedName
if GenerateProperties:
varname = '_'+varname
wrt(' def get%s(self): return self.%s\n' % wrt(' def get%s(self): return self.%s\n' %
(make_gs_name(name), mappedName)) (make_gs_name(name), varname))
gsName = make_gs_name(name) gsName = make_gs_name(name)
wrt(' def set%s(self, %s):\n' % ( wrt(' def set%s(self, value):\n' % (
gsName, mappedName)) gsName,))
wrt(' self.%s = %s\n' %(mappedName, mappedName)) wrt(' self.%s = value\n' %(varname))
if PostSetter is not None: if PostSetter is not None:
wrt(' %s\n' % (PostSetter)) wrt(' %s\n' % (PostSetter))
if GenerateProperties: if GenerateProperties:
wrt(' %sProp = property(get%s, set%s)\n' % # wrt(' %sProp = property(get%s, set%s)\n' %
# (name, gsName, gsName))
wrt(' %s = property(get%s, set%s)\n' %
(name, gsName, gsName)) (name, gsName, gsName))
if element.getSimpleContent() or element.isMixed(): if element.getSimpleContent() or element.isMixed():
wrt(' def get%s_(self): return self.valueOf_\n' % ( wrt(' def get%s_(self): return self.valueOf_\n' % (
...@@ -5169,6 +5190,7 @@ import warnings as warnings_ ...@@ -5169,6 +5190,7 @@ import warnings as warnings_
#xmldisable# from lxml import etree as etree_ #xmldisable# from lxml import etree as etree_
#xmldisable#except ImportError: #xmldisable#except ImportError:
#xmldisable# from xml.etree import ElementTree as etree_ #xmldisable# from xml.etree import ElementTree as etree_
{HeadImports}
Validate_simpletypes_ = True Validate_simpletypes_ = True
...@@ -5959,6 +5981,7 @@ except ImportError as exp: ...@@ -5959,6 +5981,7 @@ except ImportError as exp:
args1=args1, args1=args1,
command_line=command_line, command_line=command_line,
current_working_directory=current_working_directory, current_working_directory=current_working_directory,
HeadImports=HeadImports,
ExternalEncoding=ExternalEncoding, ExternalEncoding=ExternalEncoding,
preserve_cdata_tags_pat=preserve_cdata_tags_pat, preserve_cdata_tags_pat=preserve_cdata_tags_pat,
preserve_cdata_get_text=preserve_cdata_get_text, preserve_cdata_get_text=preserve_cdata_get_text,
...@@ -7245,7 +7268,6 @@ def load_config(): ...@@ -7245,7 +7268,6 @@ def load_config():
except ImportError: except ImportError:
pass pass
def fixSilence(txt, silent): def fixSilence(txt, silent):
if silent: if silent:
txt = txt.replace('#silence#', '## ') txt = txt.replace('#silence#', '## ')
...@@ -7334,7 +7356,9 @@ def main(): ...@@ -7334,7 +7356,9 @@ def main():
UseGeneratedssuperLookup, UseSourceFileAsModuleName, \ UseGeneratedssuperLookup, UseSourceFileAsModuleName, \
PreserveCdataTags, CleanupNameList, \ PreserveCdataTags, CleanupNameList, \
NoWarnings, AlwaysExportDefault, \ NoWarnings, AlwaysExportDefault, \
UppercaseEnums, CreateMandatoryChildren, PostSetter UppercaseEnums, CreateMandatoryChildren, \
PostSetter, PreCtor, PostCtor, \
HeadImports
outputText = True outputText = True
args = sys.argv[1:] args = sys.argv[1:]
try: try:
...@@ -7357,7 +7381,8 @@ def main(): ...@@ -7357,7 +7381,8 @@ def main():
'no-warnings', 'no-warnings',
'no-collect-includes', 'no-redefine-groups', 'no-collect-includes', 'no-redefine-groups',
'always-export-default', 'mixed-case-enums', 'always-export-default', 'mixed-case-enums',
'create-mandatory-children', 'post-setter=' 'create-mandatory-children', 'post-setter=',
'pre-ctor=', 'post-ctor=', 'imports='
]) ])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
...@@ -7383,6 +7408,9 @@ def main(): ...@@ -7383,6 +7408,9 @@ def main():
UppercaseEnums = True UppercaseEnums = True
CreateMandatoryChildren = False CreateMandatoryChildren = False
PostSetter = None PostSetter = None
PreCtor = None
PostCtor = None
HeadImports = ''
for option in options: for option in options:
if option[0] == '--session': if option[0] == '--session':
...@@ -7572,6 +7600,13 @@ def main(): ...@@ -7572,6 +7600,13 @@ def main():
CreateMandatoryChildren = True CreateMandatoryChildren = True
elif option[0] == '--post-setter': elif option[0] == '--post-setter':
PostSetter = option[1] PostSetter = option[1]
elif option[0] == '--pre-ctor':
PreCtor = option[1]
elif option[0] == '--post-ctor':
PostCtor = option[1]
elif option[0] == '--imports':
HeadImports = option[1]
if showVersion: if showVersion:
print('generateDS.py version %s' % VERSION) print('generateDS.py version %s' % VERSION)
sys.exit(0) sys.exit(0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment