propoagate pairs down inheritance trees
This commit is contained in:
parent
c4e6c9beb8
commit
f949e18d7e
|
@ -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.
|
i scan in all of my paper school- and coursework so i can refer to it in the future from the past.
|
||||||
|
|
||||||
## todo
|
## todo
|
||||||
[ ] propogate pairs down inheritance trees
|
[x] propogate pairs down inheritance trees
|
||||||
|
|
||||||
## license
|
## license
|
||||||
This is free and unencumbered software released into the public domain.
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
21
record.py
21
record.py
|
@ -17,6 +17,8 @@ class Record:
|
||||||
self.children = {}
|
self.children = {}
|
||||||
self.parents = {}
|
self.parents = {}
|
||||||
|
|
||||||
|
self.propagated = False
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.data[item]
|
return self.data[item]
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ class RecordCollection():
|
||||||
with filewrapper(file, "r") as fd:
|
with filewrapper(file, "r") as fd:
|
||||||
self._fromFile(fd)
|
self._fromFile(fd)
|
||||||
self._parent()
|
self._parent()
|
||||||
|
self._propagate()
|
||||||
|
|
||||||
def _fromFile(self, fd):
|
def _fromFile(self, fd):
|
||||||
lines = [i.rstrip() for i in fd.readlines()]
|
lines = [i.rstrip() for i in fd.readlines()]
|
||||||
|
@ -112,3 +115,21 @@ class RecordCollection():
|
||||||
lines[i] += "\n"
|
lines[i] += "\n"
|
||||||
|
|
||||||
fd.writelines(lines)
|
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])
|
||||||
|
|
Loading…
Reference in New Issue