-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
65 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Any, Dict, List, Tuple | ||
from xml.etree import ElementTree as ET | ||
|
||
|
||
def convert_xml_to_names_and_values(xml) -> Dict[str, str]: | ||
names_and_values = dict() | ||
elements = get_all_elements_in_xml_with_child_called_name(xml) | ||
for element in elements: | ||
name, value = _get_names_and_values(element) | ||
names_and_values[name] = value | ||
return names_and_values | ||
|
||
|
||
def get_all_elements_in_xml_with_child_called_name(xml): | ||
# This finds all elements with a "name" element, but ignores the first one as it's the root | ||
elements = xml.findall(".//Name/..")[1:] | ||
return elements | ||
|
||
|
||
def _get_names_and_values(element) -> Tuple[str, str]: | ||
name = element.find("Name") | ||
if name is not None and hasattr(name, "text"): | ||
name = name.text | ||
value = element.find("Val") | ||
if value is not None and hasattr(value, "text"): | ||
value = value.text | ||
# TODO hmmmm, should we get choices here and store them somewhere? not sure. | ||
return name, value | ||
|
||
|
||
def set_value_in_dae_xml(elements: List[ET.ElementTree], name: str, value: Any): | ||
"""TODO add some docs here pls""" | ||
if value is not None: | ||
if isinstance(value, Enum): | ||
value = value.value | ||
for i in elements: | ||
if i.find("Name").text == name: | ||
i.find("Val").text = str(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters