Skip to content

Commit a165153

Browse files
committed
[section] Add Leaf-Export
Method to export single leaf of odml document, starting at specified section. Includes properties of selected section, but no subsections.
1 parent 81d7cf3 commit a165153

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

odml/section.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8
22
import collections
33
import uuid
4+
from copy import deepcopy
45

56
from . import base
67
from . import format
@@ -638,3 +639,23 @@ def pprint(self, indent=2, max_depth=1, max_length=80, current_depth=0):
638639
print("{} {} [{}]\n{}[...]".format(child_sec_indent,
639640
s.name, s.type,
640641
more_indent))
642+
643+
def export_leaf(self):
644+
"""
645+
Export leaf, start at section. Includes section properties, not subsections.
646+
"""
647+
curr = self.parent
648+
child = self.clone(children=False, keep_id=True)
649+
650+
for prop in self.properties:
651+
child.append(prop.clone(keep_id=True))
652+
653+
par = child
654+
655+
while curr is not None:
656+
par = curr.clone(children=False, keep_id=True)
657+
par.append(child)
658+
child = par
659+
curr = curr.parent
660+
661+
return par

0 commit comments

Comments
 (0)