[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9373 - trunk/gnue-common/src/definitions
From: |
reinhard |
Subject: |
[gnue] r9373 - trunk/gnue-common/src/definitions |
Date: |
Mon, 12 Feb 2007 12:07:35 -0600 (CST) |
Author: reinhard
Date: 2007-02-12 12:07:35 -0600 (Mon, 12 Feb 2007)
New Revision: 9373
Modified:
trunk/gnue-common/src/definitions/GParserHelpers.py
Log:
Also merge attributes on merging of two objects, define whether to overwrite or
not. This is necessary for merging country specific versions of forms.
issue153 testing
Modified: trunk/gnue-common/src/definitions/GParserHelpers.py
===================================================================
--- trunk/gnue-common/src/definitions/GParserHelpers.py 2007-02-12 13:09:36 UTC
(rev 9372)
+++ trunk/gnue-common/src/definitions/GParserHelpers.py 2007-02-12 18:07:35 UTC
(rev 9373)
@@ -169,21 +169,30 @@
# Merge another object tree with this tree
# ---------------------------------------------------------------------------
- def merge (self, other, maxIdLength = None):
+ def merge (self, other, maxIdLength = None, overwrite=False):
"""
Merge another object tree into this tree.
- The node itself is left untouched. All child nodes that don't exist in the
- other tree are left untouched, too. All child nodes that exist in the other
- tree are replaced by that version. All nodes that exist only in the other
- tree are copied to the end of this tree.
+ All attributes and child nodes from the other object are merged into this
+ object. If any child node exists in both objects with the same name (id),
+ the merge is done recursively.
@param other: L{ParserObj} tree to be merged into this object tree
+ @param maxIdLength: maximum length of the name to compare, useful if any of
+ the objects has the identifier truncated
+ @param overwrite: whether attributes and children of the other object
+ should overwrite attributes and children of this object
"""
if self.__class__ != other.__class__:
- raise AssignmentTypeError, (self, source)
+ raise AssignmentTypeError, (self, other)
+ # First copy all attributes from the other object.
+ if hasattr(other, "_listedAttributes"):
+ for attribute in other._listedAttributes:
+ if overwrite or (attribute not in self._listedAttributes):
+ self.__dict__[attribute] = other.__dict__[attribute]
+
# We keep a mapping of all our children
mine = {}
for mc in self._children:
@@ -192,7 +201,8 @@
for otherChild in other._children:
# ... wether we have to start a recursive merge ...
if otherChild._id_ (maxIdLength) in mine:
- mine [otherChild._id_ (maxIdLength)].merge (otherChild)
+ mine [otherChild._id_ (maxIdLength)].merge (otherChild, maxIdLength,
+ overwrite)
# ... or we can copy the subtree
else:
new = otherChild.__class__ (self)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9373 - trunk/gnue-common/src/definitions,
reinhard <=