mirror of
https://github.com/KrisKennaway/pyapple2disk.git
synced 2024-06-10 16:29:28 +00:00
f3bde766bf
objects associated to the container, and builds a tree of child containers with support for depth-first recursion Convert all of the disk container classes to use Container() and register themselves with this tree. This constructs a hierarchy of container objects rooted in Disk that describe the structures found on the disk image. Convert most of the print statements and some of the assertions to register Anomaly records instead Fix/improve some of the __str__ representations
21 lines
592 B
Python
21 lines
592 B
Python
class Container(object):
|
|
"""Generic container type, every structure on the disk extends from this."""
|
|
|
|
def __init__(self):
|
|
self.anomalies = []
|
|
|
|
self.parent = None
|
|
self.children = []
|
|
|
|
def AddChild(self, child):
|
|
assert child.parent is None, "%s already has parent %s" % (child, child.parent)
|
|
|
|
self.children.append(child)
|
|
child.parent = self
|
|
|
|
def Recurse(self, callback):
|
|
"""Depth-first recursive traversal of children."""
|
|
for child in self.children:
|
|
callback(child)
|
|
child.Recurse(callback)
|