mirror of
https://github.com/libretro/libretro-dat-pull.git
synced 2024-11-26 18:10:31 +00:00
New dat generation script
This commit is contained in:
parent
75c3371bab
commit
0cf07e6216
@ -95,9 +95,9 @@ Now we just have to tell the script to generate the dat file (this will take aro
|
||||
For this example the command would be
|
||||
|
||||
~~~
|
||||
[thomas@HackBox libretro-dat-pull]$ python2 generate-libretrodat.py 38 '{"game":{"rom":{"serial":"romSerial","image":"romFileName"},"name":"romExtensionlessFileName","description":"romExtensionlessFileName"}}' ps.dat
|
||||
[thomas@HackBox libretro-dat-pull]$ ./generate-dat.py 38 '{"game":{"rom":{"serial":"romSerial","image":"romFileName"},"name":"romExtensionlessFileName","description":"romExtensionlessFileName"}}' ps
|
||||
~~~
|
||||
You can even add multiple dictionaries the syntax is
|
||||
~~~
|
||||
python2 generate-libretrodat.py sqlite id string1 string1.dat string2 string2.dat
|
||||
python2 generate-libretrodat.py sqlite id string1 string2 system_dat_prefix
|
||||
~~~
|
||||
|
@ -1,77 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys,ast,re
|
||||
import openvgdb
|
||||
|
||||
string='{"game":{"rom":{"serial":"romSerial","image":"romFileName"},"name":"romExtensionlessFileName","description":"romExtensionlessFileName"}}'
|
||||
par=ast.literal_eval(string)
|
||||
games=[]
|
||||
game=[]
|
||||
val='game'
|
||||
|
||||
def fix(foo):
|
||||
old=chr(int('0A',16))
|
||||
new=chr(int('0D',16))+chr(int('0A',16))
|
||||
return re.sub('('+old+')',new,foo)
|
||||
|
||||
def parse(a,level,nnl=False):
|
||||
ret=[]
|
||||
last=[]
|
||||
check=['crc','md5','sha1','serial']
|
||||
for entry in a:
|
||||
if type(a[entry])==type({}) and entry=="game":
|
||||
last.append("\t"*level+str(entry)+" (\n")
|
||||
last.append(parse(a[entry],level+1))
|
||||
last.append("\t"*level+")\n")
|
||||
elif type(a[entry])==type({}) and entry=="rom":
|
||||
last.append("\t%s ( " % (str(entry)) )
|
||||
last.append(parse(a[entry],level,True))
|
||||
last.append(")\n")
|
||||
else:
|
||||
value=game[a[entry]]
|
||||
if type(value)==type(42) or entry in check:
|
||||
if nnl==False:
|
||||
ret.append("\t"*level+str(entry)+" "+str(value)+" ")
|
||||
else:
|
||||
ret.append(str(entry)+" "+str(value)+" ")
|
||||
else:
|
||||
try:
|
||||
if nnl==False:
|
||||
ret.append("\t"*level+str(entry)+' "'+str(value).encode('utf-8')+"\"")
|
||||
else:
|
||||
ret.append(str(entry)+' "'+str(value).encode('utf-8')+"\" ")
|
||||
except:
|
||||
print 'Couldn\'t parse'
|
||||
print value
|
||||
if nnl==False:
|
||||
#check if we need a newline
|
||||
ret.append("\n")
|
||||
return "".join(ret)+"".join(last)
|
||||
|
||||
if len(sys.argv)%2!=0:
|
||||
print 'Something is wrong.Check your parameters again (the count is off)'
|
||||
quit()
|
||||
|
||||
O=openvgdb.vgdb('openvgdb.sqlite')
|
||||
print 'Getting the game list.This can take a while...'
|
||||
header="clrmamepro (\n\
|
||||
\tname \""+O.get_systems()[int(sys.argv[1])]+"\"\n\
|
||||
)\n"
|
||||
games=O.get_console(sys.argv[1])
|
||||
print 'Done.Starting to convert'
|
||||
#print game
|
||||
#print parse(par,0)
|
||||
#f.write(parse(par,0))
|
||||
#quit()
|
||||
|
||||
|
||||
for i in range(0,(len(sys.argv)-2)/2):
|
||||
string=sys.argv[2+i*2]
|
||||
par=ast.literal_eval(string)
|
||||
f=open(sys.argv[3+i*2],"w")
|
||||
print 'writing '+sys.argv[3+i*2]
|
||||
f.write(fix(header))
|
||||
for game in games:
|
||||
f.write(fix(parse(par,0)))
|
||||
f.close()
|
||||
print 'Done everything went according to plan'
|
Loading…
Reference in New Issue
Block a user