propoagate pairs down inheritance trees

This commit is contained in:
randomuser 2021-11-23 11:16:20 -06:00
parent c4e6c9beb8
commit f949e18d7e
2 changed files with 23 additions and 2 deletions

View File

@ -7,7 +7,7 @@ this repository contains a variety of tools for managing archives. from scanning
i scan in all of my paper school- and coursework so i can refer to it in the future from the past.
## todo
[ ] propogate pairs down inheritance trees
[x] propogate pairs down inheritance trees
## license
This is free and unencumbered software released into the public domain.

View File

@ -17,6 +17,8 @@ class Record:
self.children = {}
self.parents = {}
self.propagated = False
def __getitem__(self, item):
return self.data[item]
@ -30,7 +32,8 @@ class RecordCollection():
def __init__(self, file):
with filewrapper(file, "r") as fd:
self._fromFile(fd)
self._parent()
self._parent()
self._propagate()
def _fromFile(self, fd):
lines = [i.rstrip() for i in fd.readlines()]
@ -112,3 +115,21 @@ class RecordCollection():
lines[i] += "\n"
fd.writelines(lines)
def _resolveNode(self, node):
if not node.parents:
return
elif node.propagated:
return
else:
for i in node.parents:
if not node.parents[i].propagated:
self._resolveNode(node.parents[i])
for j in node.parents[i].data:
if not j in node.data:
node.data[j] = node.parents[i].data[j]
node.propagated = True
def _propagate(self):
for i in self.objects:
self._resolveNode(self.objects[i])