Change xml file backup
This commit is contained in:
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
import lxml.etree as ET
|
import lxml.etree as ET
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import click
|
import click
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
def write_xml_data(root: ET.Element, file_path: Path, pretty: bool = True) -> None:
|
def write_xml_data(root: ET.Element, file_path: Path, pretty: bool = True) -> None:
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
file_path.rename(file_path.with_suffix(".bak"))
|
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)
|
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty)
|
||||||
if pretty:
|
if pretty:
|
||||||
# Parse the XML string to ensure proper indentation
|
# Parse the XML string to ensure proper indentation
|
||||||
|
|||||||
Reference in New Issue
Block a user