Created
August 5, 2020 19:31
-
-
Save Temetra/885b9517eef899603cf5a6879cf1adf5 to your computer and use it in GitHub Desktop.
Replacement report generation (XML format) for Tuning Error Notifier by SCUMBUMBO (Sims 4 mod)
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
# Generates the XML report in a temporary file. This is called from the dialog_callback | |
# or the notification button's cheat command. A callback is registered to be called at Python | |
# exit time to remove the temporary file. | |
def generate_report(self): | |
(tmp_fd, filename) = tempfile.mkstemp(suffix='.xml', text=True) | |
with os.fdopen(tmp_fd, 'w') as fp: | |
fp.write('<?xml version="1.0"?>') | |
fp.write('\n<report on="{}">'.format(datetime.datetime.now().strftime('%c'))) | |
for name in self._log_entries: | |
fp.write('\n\t<source name="{}">'.format(name)) | |
for idx, msg in enumerate(self._log_entries[name]): | |
if name in msg: | |
if idx > 0: | |
fp.write('\n\t\t]]></error>') | |
fp.write('\n\t\t<error description="{}"><![CDATA['.format(html.escape(msg))) | |
else: | |
fp.write('\n\t\t\t{}'.format(msg)) | |
fp.write('\n\t\t]]></error>') | |
fp.write('\n\t</source>') | |
fp.write('\n</report>') | |
webbrowser.open('file:///{}'.format(filename), new=2) | |
atexit.register(self.remove_tempfile, filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment