Skip to content

Commit 98aa213

Browse files
committed
[tools/versionConv] Change same named obj indexing
Closes #289 Previously all same named odml.Sections within a document got indexed upon conversion. With these changes, only same named odml.Sections that reside on the same level are indexed.
1 parent 6c86f9a commit 98aa213

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

odml/tools/version_converter.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,34 +370,38 @@ def _handle_value(self, value, log_id):
370370
@classmethod
371371
def _replace_same_name_entities(cls, tree):
372372
"""
373-
Changes same section names in the doc by adding <-{index}> to the next section occurrences.
373+
Changes same section names in the doc by adding <-{index}>
374+
to the next section occurrences.
374375
:param tree: ElementTree of the doc
375376
:return: ElementTree
376377
"""
377378
sec_map = {}
378379
prop_map = {}
379380
root = tree.getroot()
380381
for sec in root.iter("section"):
381-
n = sec.find("name")
382-
if n is not None:
383-
cls._change_entity_name(sec_map, n)
382+
383+
sec_name = sec.find("name")
384+
if sec_name is not None:
385+
cls._change_entity_name(tree, sec_map, sec_name)
384386
else:
385387
raise Exception("Section attribute name is not specified")
388+
386389
for prop in sec.iter("property"):
387390
if prop.getparent() == sec:
388-
n = prop.find("name")
389-
if n is not None:
390-
cls._change_entity_name(prop_map, n)
391+
prop_name = prop.find("name")
392+
if prop_name is not None:
393+
cls._change_entity_name(tree, prop_map, prop_name)
391394
prop_map.clear()
392395
return tree
393396

394397
@staticmethod
395-
def _change_entity_name(elem_map, name):
396-
if name.text not in elem_map:
397-
elem_map[name.text] = 1
398+
def _change_entity_name(tree, elem_map, name):
399+
named_path = "%s:%s" % (tree.getpath(name.getparent().getparent()), name.text)
400+
if named_path not in elem_map:
401+
elem_map[named_path] = 1
398402
else:
399-
elem_map[name.text] += 1
400-
name.text += "-" + str(elem_map[name.text])
403+
elem_map[named_path] += 1
404+
name.text += "-" + str(elem_map[named_path])
401405

402406
def _log(self, msg):
403407
"""

0 commit comments

Comments
 (0)