From 179e97b20006cb32328bf8b8fd255c9aa98118df Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 22 May 2017 21:31:19 +0200 Subject: [PATCH] Warn user if a xml cannot be parsed --- .../resource.language.en_gb/strings.po | 5 +++ resources/lib/utils.py | 37 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index e43dbf53..aac7adc3 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1919,3 +1919,8 @@ msgstr "" msgctxt "#39715" msgid "items" msgstr "" + +# Error message if an xml, e.g. advancedsettings.xml cannot be parsed (xml is screwed up; formated the wrong way). Do NOT replace {0} and {1}! +msgctxt "#39716" +msgid "Kodi cannot parse {0}. PKC will not function correctly. Please visit {1} and correct your file!" +msgstr "" diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 396488ea..0a64942b 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -536,9 +536,16 @@ def guisettingsXML(): try: xmlparse = etree.parse(xmlpath) - except: + except IOError: # Document is blank or missing root = etree.Element('settings') + except etree.ParseError: + log.error('Error parsing %s' % xmlpath) + # "Kodi cannot parse {0}. PKC will not function correctly. Please visit + # {1} and correct your file!" + dialog('ok', language(29999), language(39716).format( + 'guisettings.xml', 'http://kodi.wiki/view/userdata')) + return else: root = xmlparse.getroot() return root @@ -620,6 +627,14 @@ def advancedsettings_xml(node_list, new_value=None, attrib=None, return None, None # Create topmost xml entry tree = etree.ElementTree(element=etree.Element('advancedsettings')) + except etree.ParseError: + log.error('Error parsing %s' % path) + # "Kodi cannot parse {0}. PKC will not function correctly. Please visit + # {1} and correct your file!" + dialog('ok', language(29999), language(39716).format( + 'advancedsettings.xml', + 'http://kodi.wiki/view/Advancedsettings.xml')) + return None, None root = tree.getroot() element = root @@ -653,8 +668,15 @@ def sourcesXML(): try: xmlparse = etree.parse(xmlpath) - except: # Document is blank or missing + except IOError: # Document is blank or missing root = etree.Element('sources') + except etree.ParseError: + log.error('Error parsing %s' % xmlpath) + # "Kodi cannot parse {0}. PKC will not function correctly. Please visit + # {1} and correct your file!" + dialog('ok', language(29999), language(39716).format( + 'sources.xml', 'http://kodi.wiki/view/sources.xml')) + return else: root = xmlparse.getroot() @@ -690,18 +712,25 @@ def passwordsXML(): # To add network credentials path = tryDecode(xbmc.translatePath("special://userdata/")) xmlpath = "%spasswords.xml" % path + dialog = xbmcgui.Dialog() try: xmlparse = etree.parse(xmlpath) - except: + except IOError: # Document is blank or missing root = etree.Element('passwords') skipFind = True + except etree.ParseError: + log.error('Error parsing %s' % xmlpath) + # "Kodi cannot parse {0}. PKC will not function correctly. Please visit + # {1} and correct your file!" + dialog.ok(language(29999), language(39716).format( + 'passwords.xml', 'http://forum.kodi.tv/')) + return else: root = xmlparse.getroot() skipFind = False - dialog = xbmcgui.Dialog() credentials = settings('networkCreds') if credentials: # Present user with options