Skip to content

Commit 9915a72

Browse files
committed
[doc] Add Pretty Print
Add pprint method showing document information and section/ property tree. Related to issue #319.
1 parent b0170a8 commit 9915a72

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

odml/doc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,21 @@ def get_terminology_equivalent(self):
141141
return None
142142
term = terminology.load(self.repository)
143143
return term
144+
def pprint(self, indent=2, max_depth=1, max_length=80, current_depth=0):
145+
"""
146+
Pretty print method to visualize Document-Section trees.
147+
148+
:param indent: number of leading spaces for every child Section or Property.
149+
:param max_depth: maximum number of hierarchical levels printed from the
150+
starting Section.
151+
:param max_length: maximum number of characters printed in one line.
152+
:param current_depth: number of hierarchical levels printed from the
153+
starting Section.
154+
"""
155+
doc_str = "[{} [{}] {}, sections: {}, repository: {}]".format(self.author, self.version,
156+
self.date, len(self._sections), self.repository)
157+
print(doc_str)
158+
159+
for s in self._sections:
160+
s.pprint(current_depth=current_depth+1, max_depth=max_depth,
161+
indent=indent, max_length=max_length)

0 commit comments

Comments
 (0)