From 5778c1c9eece2bc0df442b959303cede49bfdf30 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 19 Dec 2021 18:00:43 +0100 Subject: [PATCH] enhance reload file --- extensions/fablabchemnitz/reload/reload.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/extensions/fablabchemnitz/reload/reload.py b/extensions/fablabchemnitz/reload/reload.py index f73c0643..09cac764 100644 --- a/extensions/fablabchemnitz/reload/reload.py +++ b/extensions/fablabchemnitz/reload/reload.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import inkex from lxml import etree @@ -22,10 +23,16 @@ class Reload(inkex.EffectExtension): originalDefs = originalRoot.find("{http://www.w3.org/2000/svg}defs") originalRoot.clear() #drop all children and attributes from root - stream = open(self.document_path(), 'r') - p = etree.XMLParser(huge_tree=True) - doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True)) - stream.close() + if not os.path.exists(currentDoc): + self.msg("The input file does not exist (anymore). Please check and try again.") + exit(1) + + with open(currentDoc, 'r') as stream: + try: + doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True)) + except Exception as e: + inkex.utils.debug("Malformed file: {}".format(e)) + exit(1) copyRoot = doc.getroot() copyNamedview = copyRoot.find(inkex.addNS('namedview', 'sodipodi'))