From e0576c757912702d76c31d87948d40a633babda6 Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 30 Aug 2023 08:12:15 +0200 Subject: [PATCH] =?UTF-8?q?fbneo=5Froms:=20peque=C3=B1o=20retoque=20en=20e?= =?UTF-8?q?l=20parse=20de=20argumentos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fbneo_roms_by_manufacturer.py | 68 +++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/fbneo_roms_by_manufacturer.py b/fbneo_roms_by_manufacturer.py index a9b0028..4fbb4e6 100644 --- a/fbneo_roms_by_manufacturer.py +++ b/fbneo_roms_by_manufacturer.py @@ -10,25 +10,31 @@ import sys import getopt from xml.dom import minidom -opt_manufacturer = '' -opt_list = 'no' -opt_dat = '' -opt_src_roms = '' -opt_dst_roms = '' -opt_copy = 'no' -opt_sort = 'no' - +# Inicialización de las opciones +opt_manufacturer = "" +opt_list = "no" +opt_dat = "" +opt_src_roms = "" +opt_dst_roms = "" +opt_copy = "no" +opt_sort = "no" ignore_list = ["DECO Cassette"] - +# Comprueba los parametros try: - opts, args = getopt.getopt(sys.argv[1:],"hd:lm:ci:o:s",["list","manufacturer=","dat=","copy","input=","output=","sort"]) + opts, args = getopt.getopt( + sys.argv[1:], + "hlm:d:ci:o:s", + ["help", "list", "manufacturer=", "dat=", "copy", "input=", "output=", "sort"], + ) + except getopt.GetoptError: - print ('test.py -i -o ') + print("test.py -i -o ") sys.exit(2) + for opt, arg in opts: - if opt == '-h': - print ('test.py -i -o ') + if opt in ("-h", "--help"): + print("test.py -i -o ") sys.exit() elif opt in ("-l", "--list"): opt_list = "yes" @@ -46,13 +52,13 @@ for opt, arg in opts: opt_sort = "yes" # Importa el xml -if opt_dat == '' or not os.path.isfile(opt_dat): +if opt_dat == "" or not os.path.isfile(opt_dat): sys.exit(2) print("Parsing {} file".format(opt_dat)) file = minidom.parse(opt_dat) # Lista los desarrolladores -if opt_list == "yes" and opt_manufacturer == '': +if opt_list == "yes" and opt_manufacturer == "": print("List of all manufacturers:") manufacturers = [] games = file.getElementsByTagName("game") @@ -68,7 +74,7 @@ if opt_list == "yes" and opt_manufacturer == '': print(i) # Lista los juegos de un desarrollador -if opt_list == "yes" and opt_manufacturer != '': +if opt_list == "yes" and opt_manufacturer != "": print("List of all {} games".format(opt_manufacturer)) games = file.getElementsByTagName("game") for game in games: @@ -76,11 +82,20 @@ if opt_list == "yes" and opt_manufacturer != '': isbios = game.getAttribute("isbios") manufacturer = game.getElementsByTagName("manufacturer")[0] description = game.getElementsByTagName("description")[0] - if manufacturer.firstChild.data == opt_manufacturer and not cloneof and not isbios: + if ( + manufacturer.firstChild.data == opt_manufacturer + and not cloneof + and not isbios + ): print("%s" % (description.firstChild.data)) # Copia los juegos seleccionados -if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_roms) and opt_manufacturer != '': +if ( + opt_copy == "yes" + and os.path.isdir(opt_src_roms) + and os.path.isdir(opt_dst_roms) + and opt_manufacturer != "" +): print("Copying all {} games".format(opt_manufacturer)) notfound = [] ignored_games = [] @@ -92,7 +107,11 @@ if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_r isbios = game.getAttribute("isbios") manufacturer = game.getElementsByTagName("manufacturer")[0] description = game.getElementsByTagName("description")[0] - if manufacturer.firstChild.data == opt_manufacturer and not cloneof and not isbios: + if ( + manufacturer.firstChild.data == opt_manufacturer + and not cloneof + and not isbios + ): for element in ignore_list: if description.firstChild.data.find(element) != -1: ignored_games.append(description.firstChild.data) @@ -101,7 +120,7 @@ if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_r src = os.path.join(opt_src_roms, name) if opt_sort == "yes": x = manufacturer.firstChild.data - x = x.replace(r'/', r'-') + x = x.replace(r"/", r"-") dst = os.path.join(opt_dst_roms, x, name) if not os.path.isdir(os.path.join(opt_dst_roms, x)): os.mkdir(os.path.join(opt_dst_roms, x)) @@ -121,7 +140,12 @@ if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_r print(game) # Copia todos los juegos -if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_roms) and opt_manufacturer == '': +if ( + opt_copy == "yes" + and os.path.isdir(opt_src_roms) + and os.path.isdir(opt_dst_roms) + and opt_manufacturer == "" +): print("Copying all games") notfound = [] games = file.getElementsByTagName("game") @@ -135,7 +159,7 @@ if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_r src = os.path.join(opt_src_roms, name) if opt_sort == "yes": x = manufacturer.firstChild.data - x = x.replace(r'/', r'-') + x = x.replace(r"/", r"-") dst = os.path.join(opt_dst_roms, x, name) if not os.path.isdir(os.path.join(opt_dst_roms, x)): os.mkdir(os.path.join(opt_dst_roms, x))