Commit 839999a2 authored by De Boissieu Florian's avatar De Boissieu Florian

add attributes 'parents', 'children', 'attributes' to classes and add post-setter option

--HG--
branch : settersOptions
parent dfe21aaf
......@@ -145,6 +145,8 @@ Options:
--fix-type-names="oldname1:newname1;oldname2:newname2;..."
Fix up (replace) complex type names.
--version Print version and exit.
--post-setter add code at the end of setter (executed only if
input argument is not None)
Usage example:
......@@ -3849,7 +3851,9 @@ def generateBuildStandard_1(
else:
name = mappedName
name = cleanupName(name)
s1 = " self.%s.append(obj_)\n" % (name, )
capName = make_gs_name(name)
s1 = " self.add%s(obj_)\n" % (capName, )
else:
substitutionGroup = child.getAttrs().get('substitutionGroup')
if substitutionGroup is not None:
......@@ -3858,7 +3862,8 @@ def generateBuildStandard_1(
else:
name = mapName(headName)
name = cleanupName(name)
s1 = " self.%s = obj_\n" % (name, )
capName = make_gs_name(name)
s1 = " self.set%s(obj_)\n" % (capName, )
wrt(s1)
wrt(" obj_.original_tagname_ = '%s'\n" % (origName, ))
#
......@@ -4186,6 +4191,23 @@ def generateCtor(wrt, prefix, element):
# which member of the xs:substitutionGroup this specific element
# came from.
wrt(' self.original_tagname_ = None\n')
# if AddAttributes:
wrt(" self.troot = get_gs_troot('plots', '%s')\n" % cleanupName(elName))
attrDefs = element.getAttributeDefs()
attribNameList=[]
for key in element.getAttributeDefsList():
attrDef = attrDefs[key]
mappedName = cleanupName(attrDef.getName())
name = mapName(mappedName)
attribNameList.append(name)
wrt(" self.attrib = %s\n" % ("['" + "', '".join(attribNameList) + "']"))
childrenNameList=[]
for child in element.getChildren():
name = cleanupName(child.getCleanName())
childrenNameList.append(name)
wrt(" self.children = %s\n" % ("['" + "', '".join(childrenNameList) + "']"))
wrt(" self.parent = None\n")
parentName, parent = getParentName(element)
if parentName:
if parent.getFullyQualifiedName() in AlreadyGenerated:
......@@ -4199,10 +4221,12 @@ def generateCtor(wrt, prefix, element):
wrt(' super(%s%s, self).__init__(%s)\n' % (
prefix, elName, s2, ))
attrDefs = element.getAttributeDefs()
attribNameList=[]
for key in element.getAttributeDefsList():
attrDef = attrDefs[key]
mappedName = cleanupName(attrDef.getName())
name = mapName(mappedName)
attribNameList.append(name)
if name == element.getCleanName():
mbrname = name + '_member'
else:
......@@ -4238,8 +4262,12 @@ def generateCtor(wrt, prefix, element):
attrVal = "_cast(%s, %s)" % (pythonType, mbrname, )
wrt(' self.%s = %s\n' % (name, attrVal, ))
# Generate member initializers in ctor.
childrenNameList=[]
for child in element.getChildren():
name = cleanupName(child.getCleanName())
unmappedName = cleanupName(child.getName())
capName = make_gs_name(unmappedName)
childrenNameList.append(name)
if name == element.getCleanName():
mbrname = name + '_member'
else:
......@@ -4319,7 +4347,9 @@ def generateCtor(wrt, prefix, element):
wrt(' else:\n')
wrt(' self.%s = %s\n' % (name, mbrname))
else:
wrt(' self.%s = %s\n' % (name, mbrname))
# wrt(' self.%s = %s\n' % (name, mbrname))
wrt(' self.%s = None\n' % (name))
wrt(' self.set%s(%s)\n' % (capName, mbrname))
# validate if it is a simple type. Validation shows
# a warning so no fear that an error would rise.
typeName = child.getSimpleType()
......@@ -4338,6 +4368,11 @@ def generateCtor(wrt, prefix, element):
wrt(' self.extensiontype_ = extensiontype_\n')
if element.isMixed():
wrt(MixedCtorInitializers)
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
# end generateCtor
......@@ -4719,18 +4754,30 @@ def generateGettersAndSetters(wrt, element):
unmappedName = cleanupName(child.getName())
capName = make_gs_name(unmappedName)
wrt(' def get%s(self): return self.%s\n' % (capName, name))
wrt(' def set%s(self, %s): self.%s = %s\n' %
(capName, name, name, name))
wrt(' def set%s(self, %s):\n' % (capName, name))
wrt(' self.%s = %s\n' % (name, name))
wrt(' if %s is not None:\n' % (name))
if child.getType() == SequenceType:
wrt(' for %s in self.%s\n' % (name, name))
wrt(' %s.parent = self\n' % (name))
else:
wrt(' self.%s.parent = self\n' % (name))
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
if child.getMaxOccurs() > 1:
wrt(' def add%s(self, value): self.%s.append(value)\n' %
(capName, name))
wrt(' def add%s(self, value):\n' % (capName))
wrt(' value.parent = self\n')
wrt(' self.%s.append(value)\n' % (name))
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
suffix = make_gs_name('at')
wrt(' def insert%s%s(self, index, value): '
'self.%s.insert(index, value)\n' %
(capName, suffix, name))
wrt(' def replace%s%s(self, index, value): '
'self.%s[index] = value\n' %
(capName, suffix, name))
wrt(' def insert%s%s(self, index, value):\n' % (capName, suffix))
wrt(' self.%s.insert(index, value)\n' % (name))
wrt(' value.parent = self\n')
wrt(' def replace%s%s(self, index, value):\n' % (capName, suffix))
wrt(' value.parent = self\n')
wrt(' self.%s[index] = value\n' % (name))
if GenerateProperties:
wrt(' %sProp = property(get%s, set%s)\n' %
(unmappedName, capName, capName))
......@@ -4742,8 +4789,11 @@ def generateGettersAndSetters(wrt, element):
wrt(' def get%s(self): return self.%s\n' %
(make_gs_name(name), mappedName))
gsName = make_gs_name(name)
wrt(' def set%s(self, %s): self.%s = %s\n' % (
gsName, mappedName, mappedName, mappedName))
wrt(' def set%s(self, %s):\n' % (
gsName, mappedName))
wrt(' self.%s = %s\n' %(mappedName, mappedName))
if PostSetter is not None:
wrt(' %s\n' % (PostSetter))
if GenerateProperties:
wrt(' %sProp = property(get%s, set%s)\n' %
(name, gsName, gsName))
......@@ -7284,7 +7334,7 @@ def main():
UseGeneratedssuperLookup, UseSourceFileAsModuleName, \
PreserveCdataTags, CleanupNameList, \
NoWarnings, AlwaysExportDefault, \
UppercaseEnums, CreateMandatoryChildren
UppercaseEnums, CreateMandatoryChildren, PostSetter
outputText = True
args = sys.argv[1:]
try:
......@@ -7307,7 +7357,7 @@ def main():
'no-warnings',
'no-collect-includes', 'no-redefine-groups',
'always-export-default', 'mixed-case-enums',
'create-mandatory-children',
'create-mandatory-children', 'post-setter='
])
except getopt.GetoptError:
usage()
......@@ -7332,6 +7382,8 @@ def main():
noRedefineGroups = False
UppercaseEnums = True
CreateMandatoryChildren = False
PostSetter = None
for option in options:
if option[0] == '--session':
sessionFilename = option[1]
......@@ -7518,6 +7570,8 @@ def main():
UppercaseEnums = False
elif option[0] == '--create-mandatory-children':
CreateMandatoryChildren = True
elif option[0] == '--post-setter':
PostSetter = option[1]
if showVersion:
print('generateDS.py version %s' % VERSION)
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