From f949e18d7e17f6b3171c8f17211c667bd7c41c44 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 23 Nov 2021 11:16:20 -0600 Subject: [PATCH] propoagate pairs down inheritance trees --- README.md | 2 +- record.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 12d012e..e551c26 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/record.py b/record.py index 58b4168..31b2ad0 100644 --- a/record.py +++ b/record.py @@ -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])