duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

compatibility_xml_to_csv.py (2125B)


      1 import sys
      2 import argparse
      3 import xml.etree.ElementTree as ET
      4 
      5 
      6 def convert_list(filename, separator=','):
      7     fields = ["Game Code", "Game Title", "Region", "Compatibility", "Upscaling Issues", "Version tested", "Comments"]
      8     output = separator.join(fields) + "\n"
      9 
     10     tree = ET.parse(filename)
     11     for child in tree.getroot():
     12         if (child.tag != "entry"):
     13             print("!!! Skipping invalid tag '%s'" % child.tag)
     14             continue
     15 
     16         game_code = child.get("code")
     17         if game_code is None:
     18             game_code = ""
     19         game_title = child.get("title") or ""
     20         if game_title is None:
     21             game_title = ""
     22         region = child.get("region")
     23         if region is None:
     24             region = ""
     25 
     26         node = child.find("compatibility")
     27         compatibility = node.text if node is not None else ""
     28         node = child.find("upscaling-issues")
     29         upscaling_issues = node.text if node is not None else ""
     30         node = child.find("version-tested")
     31         version_tested = node.text if node is not None else ""
     32         node = child.find("comments")
     33         comments = node.text if node is not None else ""
     34 
     35         fix = None
     36         if separator == '\t':
     37             fix = lambda x: "" if x is None else x.replace('\t', '  ')
     38         elif separator == ',':
     39             fix = lambda x: "" if x is None else x if x.find(',') < 0 else ("\"%s\"" % x)
     40         else:
     41             fix = lambda x: "" if x is None else x
     42 
     43         entry_fields = [fix(game_code), fix(game_title), fix(region), fix(compatibility), fix(upscaling_issues), fix(version_tested), fix(comments)]
     44         output += separator.join(entry_fields) + "\n"
     45 
     46     return output
     47 
     48 
     49 
     50 if __name__ == "__main__":
     51     parser = argparse.ArgumentParser()
     52     parser.add_argument("--tabs", action="store_true")
     53     parser.add_argument("list_file", action="store")
     54     parser.add_argument("output_file", action="store")
     55     args = parser.parse_args()
     56 
     57     output = convert_list(args.list_file, '\t' if args.tabs else ',')
     58     output_file = open(args.output_file, "w")
     59     output_file.write(output)
     60     output_file.close()
     61 
     62