Fix superfluous CDATA tokens

This commit is contained in:
2024-11-11 14:23:08 +01:00
parent 3a1d8a449c
commit 59f482bc0e
17 changed files with 102 additions and 324 deletions

View File

@@ -4,7 +4,6 @@ import xml.etree.ElementTree as ET
from typing import Optional
from .entry import Entry
from .util import escape_text_for_xml
class RepeatEntry(Entry):
"""
@@ -51,31 +50,15 @@ class RepeatEntry(Entry):
Execute the script and update the output.
Captures stdout, stderr and exit code from each execution.
"""
try:
# Run script and capture output
process = subprocess.run(
self._script,
shell=True,
capture_output=True,
text=True
)
# Store results
self._stdout = process.stdout
self._stderr = process.stderr
self._exit_code = process.returncode
except subprocess.SubprocessError as e:
# Handle subprocess errors by capturing the error message
self._stdout = ""
self._stderr = str(e)
self._exit_code = -1
except Exception as e:
# Handle any other errors
self._stdout = ""
self._stderr = f"Error executing script: {str(e)}"
self._exit_code = -1
process = subprocess.run(
self._script,
shell=True,
capture_output=True,
text=True
)
self._stdout = process.stdout
self._stderr = process.stderr
self._exit_code = process.returncode
def generate_context(self) -> ET.Element:
"""
@@ -84,21 +67,14 @@ class RepeatEntry(Entry):
Returns:
ET.Element: XML element containing the entry's data
"""
# Create root element
element = ET.Element("repeat", {
"id": self.id,
"exit_code": str(self._exit_code) if self._exit_code is not None else "-1"
})
# Add script as CDATA or escaped text
element.text = escape_text_for_xml(self.script)
# Add stdout element
element.text = self.script
stdout_elem = ET.SubElement(element, "stdout")
stdout_elem.text = escape_text_for_xml(self._stdout)
# Add stderr element
stdout_elem.text = self._stdout
stderr_elem = ET.SubElement(element, "stderr")
stderr_elem.text = escape_text_for_xml(self._stderr)
stderr_elem.text = self._stderr
return element