Rename xml parser functions and remove unused dependencies
This commit is contained in:
+2
-22
@@ -1,6 +1,5 @@
|
||||
import lxml.etree as ET
|
||||
from pathlib import Path
|
||||
import click
|
||||
|
||||
from models.savefile import SaveFile
|
||||
from lib import sanitize_name
|
||||
@@ -10,7 +9,7 @@ def write_xml_data(savefile: SaveFile) -> None:
|
||||
if not filename.parent.exists():
|
||||
filename.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
root = _generate_xml_configuration()
|
||||
root = _generate_xml_root()
|
||||
for code in savefile.conceptCodes:
|
||||
root = add_connection(root, code.name, code.attributes)
|
||||
|
||||
@@ -72,7 +71,7 @@ def add_connection(root: ET.Element, name: str, attr_list: list[str], descriptio
|
||||
ET.SubElement(item, "SetParameter", Param="RootProperty", Source="FixedValue", Value="conceptCodes")
|
||||
return root
|
||||
|
||||
def _generate_xml_configuration() -> ET.Element:
|
||||
def _generate_xml_root() -> ET.Element:
|
||||
"""
|
||||
Generate a default XML configuration for a PowerShell connector.
|
||||
|
||||
@@ -96,22 +95,3 @@ def _generate_xml_configuration() -> ET.Element:
|
||||
ET.SubElement(environment_initialization, "Disconnect")
|
||||
ET.SubElement(root, "Schema")
|
||||
return root
|
||||
|
||||
def get_xml_data(xml_file: Path) -> ET.Element:
|
||||
"""
|
||||
Get XML data from a file. If the file does not exist, generate a default configuration.
|
||||
|
||||
Args:
|
||||
xml_file (Path): The path to the XML file.
|
||||
|
||||
Returns:
|
||||
ET.Element: The root element of the XML configuration.
|
||||
"""
|
||||
if not xml_file.exists():
|
||||
return _generate_xml_configuration()
|
||||
try:
|
||||
parser = ET.XMLParser(strip_cdata=False)
|
||||
tree = ET.parse(xml_file, parser=parser)
|
||||
return tree
|
||||
except ET.XMLSyntaxError as e:
|
||||
raise click.FileError(xml_file, f"Not a valid XML file. {e}")
|
||||
Reference in New Issue
Block a user