Refactor codebase to use a savefile and fetch data online
This commit is contained in:
+14
-10
@@ -3,16 +3,20 @@ from pathlib import Path
|
||||
import click
|
||||
from datetime import datetime
|
||||
|
||||
def write_xml_data(root: ET.Element, file_path: Path, pretty: bool = True) -> None:
|
||||
if file_path.exists():
|
||||
file_path.rename(str(file_path) + f".{datetime.now().strftime('%Y-%m-%d.%H%M%S')}.bak")
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty)
|
||||
if pretty:
|
||||
# Parse the XML string to ensure proper indentation
|
||||
parser = ET.XMLParser(remove_blank_text=True, strip_cdata=False)
|
||||
root = ET.fromstring(xml_str, parser=parser)
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty)
|
||||
file_path.write_bytes(xml_str)
|
||||
from models.savefile import SaveFile
|
||||
|
||||
def write_xml_data(savefile: SaveFile) -> None:
|
||||
filename = Path("output/CodeServerConnector.xml")
|
||||
if not filename.parent.exists():
|
||||
filename.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
root = _generate_xml_configuration()
|
||||
for code in savefile.conceptCodes:
|
||||
root = add_connection(root, code.name, code.attributes)
|
||||
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=True).decode("utf-8-sig")
|
||||
with open(filename, "w", encoding="utf-8-sig") as f:
|
||||
f.write(xml_str)
|
||||
|
||||
def sanitize_name(name: str) -> str:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user