-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv2scripts.py
executable file
·83 lines (62 loc) · 2.47 KB
/
csv2scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
"""
Copyright (C) 2019 David Boddie <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os, sys
check_headings = ["Status", "Name", "Publisher", "UEF", "ROMs", "Options", "URL", "Files"]
lines = open("roms.csv").readlines()
headings = lines.pop(0).strip().split(",")
if headings != check_headings:
sys.stderr.write("Headings in the roms.csv file were not as expected.\n")
sys.exit(1)
bf = open("batch.sh", "w")
bf.write("#!/bin/sh\n\nset -e\n\n")
tf = open("testroms.sh", "w")
tf.write("#!/bin/sh\n\nset -e\n\n")
games = 0
roms = 0
for line in lines:
pieces = line.strip().split(",")
if len(pieces) != len(check_headings):
print "Invalid entry:", pieces
continue
d = {}
for key, value in zip(check_headings, pieces):
d[key] = value
if not d["Status"].startswith("OK"):
print "Skipping", d["Name"], "-", d["Status"]
continue
elif d["URL"] == "-":
print "Skipping", d["Name"]
continue
games += 1
ROMs = d["ROMs"].split()
for i, ROM in enumerate(ROMs):
d["ROM%i" % (i + 1)] = ROM
if len(ROMs) == 1:
bf.write("UEF2ROM.py %(Options)s UEFs/%(UEF)s ROMs/%(ROM1)s\n" % d)
tf.write("elkulator -rom2 ROMs/%(ROM1)s\n" % d)
elif len(ROMs) == 2:
bf.write("UEF2ROM.py %(Options)s UEFs/%(UEF)s ROMs/%(ROM1)s ROMs/%(ROM2)s\n" % d)
tf.write("elkulator -rom2 ROMs/%(ROM1)s -rom1 ROMs/%(ROM2)s\n" % d)
else:
d["ROMs"] = " ".join(map(lambda ROM: "ROMs/" + ROM, ROMs))
d["combined"] = "ROMs/" + os.path.split(d["UEF"])[1].replace(".uef", ".rom")
bf.write("UEF2ROM.py %(Options)s UEFs/%(UEF)s %(ROMs)s\n" % d)
bf.write("cat %(ROMs)s > %(combined)s\n" % d)
tf.write("elkulator -rom2 %(combined)s\n" % d)
roms += len(ROMs)
bf.close()
tf.close()
print "%i titles" % games
print "%i ROMs" % roms