Exemple #1
0
 def __init__(self, branch: TreeBase = None, relParent=None, mode=Mode.Uid):
     self.mode = mode
     self.uid = branch.uid
     relParent = relParent or branch.root
     try:
         self.address = branch.relAddress(fromBranch=relParent)
     except:
         self.address = []
Exemple #2
0
    def addChild(self,
                 branch: TreeBase,
                 index=None,
                 force=False,
                 emitDelta=None) -> TreeBase:
        """check if a delta is necessary"""
        #print("addChild")
        emitDelta = emitDelta if emitDelta is not None else self.trackingDeltas
        #print("emitStackDelta", emitStackDelta, self.trackingDeltas)
        if emitDelta:
            # check if tree is "known" to this delta tracking scope
            try:
                relPath = branch.relAddress(fromBranch=self.deltaTrackingRoot)
                print("existing branch delta")
                structDelta = TreeStructureDelta(
                    branchRef=TreeReference(branch,
                                            relParent=self.deltaTrackingRoot),
                    oldParentRef=TreeReference(
                        branch.parent, relParent=self.deltaTrackingRoot),
                    parentRef=TreeReference(
                        branch=self,
                        relParent=self.deltaTrackingRoot,
                    ),
                    oldIndex=branch.index(),
                    newIndex=index or -1,
                    eventCode=self.StructureEvents.branchAdded)
                self.emitStackDelta(structDelta)
            except LookupError:
                print("new branch delta")
                # branch not known to delta root, make creation delta
                createDelta = TreeCreationDelta(
                    TreeReference(branch,
                                  relParent=None,
                                  mode=TreeReference.Mode.Uid),
                    parentRef=TreeReference(self,
                                            relParent=self.deltaTrackingRoot),
                    name=branch.name,
                    value=branch.value,
                    index=index or -1,
                    treeUid=branch.uid,
                    treeCls=Tree)
                self.emitStackDelta(createDelta)

            # print("readonly", self.readOnly)
            if self.readOnly:
                print("read only returning")
                return None

        # check for read only
        if self.readOnly:
            raise PermissionError(
                f"tree {self.address()} is read only, cannot set value")

        return super(Tree, self).addChild(branch, index=index)