From 77da1c8f02e2399fa9a3da3d66320a6113bfbaf3 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 25 May 2020 14:43:12 +1000 Subject: [PATCH] compatibility_xml_to_csv.py: Fix handling of broken input --- scripts/compatibility_xml_to_csv.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/compatibility_xml_to_csv.py b/scripts/compatibility_xml_to_csv.py index 33835f865..03a78d534 100644 --- a/scripts/compatibility_xml_to_csv.py +++ b/scripts/compatibility_xml_to_csv.py @@ -13,9 +13,15 @@ def convert_list(filename, separator=','): print("!!! Skipping invalid tag '%s'" % child.tag) continue - game_code = child.get("code") or "" + game_code = child.get("code") + if game_code is None: + game_code = "" game_title = child.get("title") or "" - region = child.get("region") or "" + if game_title is None: + game_title = "" + region = child.get("region") + if region is None: + region = "" node = child.find("compatibility") compatibility = node.text if node is not None else "" @@ -28,11 +34,11 @@ def convert_list(filename, separator=','): fix = None if separator == '\t': - fix = lambda x: x.replace('\t', ' ') + fix = lambda x: "" if x is None else x.replace('\t', ' ') elif separator == ',': - fix = lambda x: x if x.find(',') < 0 else ("\"%s\"" % x) + fix = lambda x: "" if x is None else x if x.find(',') < 0 else ("\"%s\"" % x) else: - fix = lambda x: x + fix = lambda x: "" if x is None else x entry_fields = [fix(game_code), fix(game_title), fix(region), fix(compatibility), fix(upscaling_issues), fix(version_tested), fix(comments)] output += separator.join(entry_fields) + "\n"