fbneo_roms: pequeño retoque en el parse de argumentos
This commit is contained in:
@@ -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 <inputfile> -o <outputfile>')
|
||||
print("test.py -i <inputfile> -o <outputfile>")
|
||||
sys.exit(2)
|
||||
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print ('test.py -i <inputfile> -o <outputfile>')
|
||||
if opt in ("-h", "--help"):
|
||||
print("test.py -i <inputfile> -o <outputfile>")
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user