fbneo_roms: pequeño retoque en el parse de argumentos
This commit is contained in:
@@ -10,25 +10,31 @@ import sys
|
|||||||
import getopt
|
import getopt
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
opt_manufacturer = ''
|
# Inicialización de las opciones
|
||||||
opt_list = 'no'
|
opt_manufacturer = ""
|
||||||
opt_dat = ''
|
opt_list = "no"
|
||||||
opt_src_roms = ''
|
opt_dat = ""
|
||||||
opt_dst_roms = ''
|
opt_src_roms = ""
|
||||||
opt_copy = 'no'
|
opt_dst_roms = ""
|
||||||
opt_sort = 'no'
|
opt_copy = "no"
|
||||||
|
opt_sort = "no"
|
||||||
ignore_list = ["DECO Cassette"]
|
ignore_list = ["DECO Cassette"]
|
||||||
|
|
||||||
|
# Comprueba los parametros
|
||||||
try:
|
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:
|
except getopt.GetoptError:
|
||||||
print ('test.py -i <inputfile> -o <outputfile>')
|
print("test.py -i <inputfile> -o <outputfile>")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt == '-h':
|
if opt in ("-h", "--help"):
|
||||||
print ('test.py -i <inputfile> -o <outputfile>')
|
print("test.py -i <inputfile> -o <outputfile>")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt in ("-l", "--list"):
|
elif opt in ("-l", "--list"):
|
||||||
opt_list = "yes"
|
opt_list = "yes"
|
||||||
@@ -46,13 +52,13 @@ for opt, arg in opts:
|
|||||||
opt_sort = "yes"
|
opt_sort = "yes"
|
||||||
|
|
||||||
# Importa el xml
|
# 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)
|
sys.exit(2)
|
||||||
print("Parsing {} file".format(opt_dat))
|
print("Parsing {} file".format(opt_dat))
|
||||||
file = minidom.parse(opt_dat)
|
file = minidom.parse(opt_dat)
|
||||||
|
|
||||||
# Lista los desarrolladores
|
# Lista los desarrolladores
|
||||||
if opt_list == "yes" and opt_manufacturer == '':
|
if opt_list == "yes" and opt_manufacturer == "":
|
||||||
print("List of all manufacturers:")
|
print("List of all manufacturers:")
|
||||||
manufacturers = []
|
manufacturers = []
|
||||||
games = file.getElementsByTagName("game")
|
games = file.getElementsByTagName("game")
|
||||||
@@ -68,7 +74,7 @@ if opt_list == "yes" and opt_manufacturer == '':
|
|||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
# Lista los juegos de un desarrollador
|
# 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))
|
print("List of all {} games".format(opt_manufacturer))
|
||||||
games = file.getElementsByTagName("game")
|
games = file.getElementsByTagName("game")
|
||||||
for game in games:
|
for game in games:
|
||||||
@@ -76,11 +82,20 @@ if opt_list == "yes" and opt_manufacturer != '':
|
|||||||
isbios = game.getAttribute("isbios")
|
isbios = game.getAttribute("isbios")
|
||||||
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
||||||
description = game.getElementsByTagName("description")[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))
|
print("%s" % (description.firstChild.data))
|
||||||
|
|
||||||
# Copia los juegos seleccionados
|
# 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))
|
print("Copying all {} games".format(opt_manufacturer))
|
||||||
notfound = []
|
notfound = []
|
||||||
ignored_games = []
|
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")
|
isbios = game.getAttribute("isbios")
|
||||||
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
||||||
description = game.getElementsByTagName("description")[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:
|
for element in ignore_list:
|
||||||
if description.firstChild.data.find(element) != -1:
|
if description.firstChild.data.find(element) != -1:
|
||||||
ignored_games.append(description.firstChild.data)
|
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)
|
src = os.path.join(opt_src_roms, name)
|
||||||
if opt_sort == "yes":
|
if opt_sort == "yes":
|
||||||
x = manufacturer.firstChild.data
|
x = manufacturer.firstChild.data
|
||||||
x = x.replace(r'/', r'-')
|
x = x.replace(r"/", r"-")
|
||||||
dst = os.path.join(opt_dst_roms, x, name)
|
dst = os.path.join(opt_dst_roms, x, name)
|
||||||
if not os.path.isdir(os.path.join(opt_dst_roms, x)):
|
if not os.path.isdir(os.path.join(opt_dst_roms, x)):
|
||||||
os.mkdir(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)
|
print(game)
|
||||||
|
|
||||||
# Copia todos los juegos
|
# 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")
|
print("Copying all games")
|
||||||
notfound = []
|
notfound = []
|
||||||
games = file.getElementsByTagName("game")
|
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)
|
src = os.path.join(opt_src_roms, name)
|
||||||
if opt_sort == "yes":
|
if opt_sort == "yes":
|
||||||
x = manufacturer.firstChild.data
|
x = manufacturer.firstChild.data
|
||||||
x = x.replace(r'/', r'-')
|
x = x.replace(r"/", r"-")
|
||||||
dst = os.path.join(opt_dst_roms, x, name)
|
dst = os.path.join(opt_dst_roms, x, name)
|
||||||
if not os.path.isdir(os.path.join(opt_dst_roms, x)):
|
if not os.path.isdir(os.path.join(opt_dst_roms, x)):
|
||||||
os.mkdir(os.path.join(opt_dst_roms, x))
|
os.mkdir(os.path.join(opt_dst_roms, x))
|
||||||
|
|||||||
Reference in New Issue
Block a user