-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild-frontend.py
More file actions
215 lines (193 loc) · 6.46 KB
/
build-frontend.py
File metadata and controls
215 lines (193 loc) · 6.46 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import os.path
from lxml import etree
import shutil
import re
import mame_roms
ROMS_PATH = '/home/drew/roms'
FRONTEND_CONFIG_ROOT = '/home/drew/dev/emu/configs/emulationstation'
SYSTEMS = [
{
'system': 'mame',
'fullname': 'Arcade',
},
{
'system': 'nes',
'fullname': 'Nintendo Entertainment System',
},
{
'system': 'fds',
'fullname': 'Famicom Disk System',
'theme': 'famicom',
},
{
'system': 'genesis',
'fullname': 'Sega Genesis / Mega Drive',
'platform': 'genesis,megadrive',
},
{
'system': 'snes',
'fullname': 'Super Nintendo',
},
{
'system': 'turbografx',
'fullname': 'TurboGrafx-16 / PC Engine',
'theme': 'pcengine',
},
{
'system': '32x',
'fullname': 'Sega 32X',
'theme': 'sega32x',
},
{
'system': 'segacd',
'fullname': 'Sega CD',
'disc': True,
},
{
'system': 'n64',
'fullname': 'Nintendo 64',
},
{
'system': 'psx',
'fullname': 'Sony PlayStation',
'disc': True,
},
{
'system': 'virtualboy',
'fullname': 'Virtual Boy',
},
{
'system': 'wii',
'fullname': 'Wii',
'ext': ['.wad'],
},
{
'system': 'gameboy',
'fullname': 'Game Boy',
'theme': 'gb',
},
{
'system': 'gamegear',
'fullname': 'Game Gear',
},
{
'system': 'gbc',
'fullname': 'Game Boy Color',
},
{
'system': 'gba',
'fullname': 'Game Boy Advance',
},
]
def get_games(system):
name = system['system']
rom_path = os.path.join(ROMS_PATH, name)
if name == 'mame':
mame_info = mame_roms.load_mame_metadata()
for rom in mame_roms.playable_roms(mame_info):
name_parts = [rom['name']]
if rom['year']:
name_parts.append('- %s' % rom['year'])
if rom['mature']:
name_parts.append('[M]')
yield {
'dir': rom_path,
'file': rom['rom'],
'name': ' '.join(name_parts),
}
else:
extensions = ['.cue'] if system.get('disc') else system.get('ext', ['.7z', '.zip'])
for k in os.listdir(rom_path):
if not any(k.endswith(ext) for ext in extensions):
continue
if k.startswith('[BIOS]'):
continue
yield {
'dir': rom_path,
'file': k,
'name': os.path.splitext(k)[0],
}
GAMELIST_DIR = os.path.join(FRONTEND_CONFIG_ROOT, 'gamelists')
LAUNCH_LINKS_DIR = os.path.join(FRONTEND_CONFIG_ROOT, 'launchlinks')
ROULETTE = '_random.game'
def make_roulette(gamelist, path):
with open(os.path.join(path, ROULETTE), 'w'):
pass
e = etree.SubElement(gamelist, 'game')
etree.SubElement(e, 'path').text = os.path.join('.', os.path.join(path, ROULETTE))
etree.SubElement(e, 'name').text = ' Surprise Me!'
#etree.SubElement(e, 'image').text = 'x.jpg'
for dir in (GAMELIST_DIR, LAUNCH_LINKS_DIR):
if os.path.exists(dir):
shutil.rmtree(dir)
os.mkdir(dir)
with open('favorites') as f:
favorites = filter(None, (ln.strip() for ln in f.readlines() if not ln.startswith('#')))
assert len(favorites) == len(set(favorites))
favorites = set(favorites)
root = etree.Element('systemList')
for system in SYSTEMS:
name = system['system']
system_launch_links_dir = os.path.join(LAUNCH_LINKS_DIR, name)
os.mkdir(system_launch_links_dir)
# space in subdir is necessary to place before other games (emulationstation groups folder
# contents in menu and uses path name as sort key)
system_fav_launch_links_dir = os.path.join(system_launch_links_dir, ' favorites')
os.mkdir(system_fav_launch_links_dir)
theme = system.get('theme', name)
e = etree.SubElement(root, 'system')
etree.SubElement(e, 'name').text = name
etree.SubElement(e, 'fullname').text = system['fullname']
etree.SubElement(e, 'path').text = system_launch_links_dir
etree.SubElement(e, 'extension').text = '.game'
etree.SubElement(e, 'command').text = '~/dev/emu/fe-launch.py %ROM%'
etree.SubElement(e, 'theme').text = theme
etree.SubElement(e, 'platform').text = system.get('platform', theme)
gamelist = etree.Element('gameList')
has_favorites = False
for game in get_games(system):
is_favorite = False
try:
favorites.remove(os.path.join(os.path.split(game['dir'])[1], game['file']))
is_favorite = True
except KeyError:
pass
has_favorites |= is_favorite
launch_path = os.path.join(system_launch_links_dir, '%s.game' % os.path.splitext(game['file'])[0])
with open(launch_path, 'w') as f:
f.write('%s\n' % os.path.join(game['dir'], game['file']))
e = etree.SubElement(gamelist, 'game')
etree.SubElement(e, 'path').text = os.path.join('.', launch_path)
etree.SubElement(e, 'name').text = game['name']
if is_favorite:
fav_launch_path = os.path.join(system_fav_launch_links_dir, '%s.game' % os.path.splitext(game['file'])[0])
with open(fav_launch_path, 'w') as f:
f.write('%s\n' % os.path.join(game['dir'], game['file']))
e = etree.SubElement(gamelist, 'game')
etree.SubElement(e, 'path').text = os.path.join('.', fav_launch_path)
etree.SubElement(e, 'name').text = game['name']
make_roulette(gamelist, system_launch_links_dir)
if has_favorites:
make_roulette(gamelist, system_fav_launch_links_dir)
gamelist_dir = os.path.join(FRONTEND_CONFIG_ROOT, 'gamelists', name)
os.mkdir(gamelist_dir)
with open(os.path.join(gamelist_dir, 'gamelist.xml'), 'w') as f:
f.write(etree.tostring(gamelist, pretty_print=True))
if favorites:
print 'unrecognized favorites:', favorites
with open(os.path.join(FRONTEND_CONFIG_ROOT, 'es_systems.cfg'), 'w') as f:
f.write(etree.tostring(root, pretty_print=True))
"""
<gameList>
<game id="1455" source="theGamesDB.net">
<desc></desc>
<image>./downloaded_images/2010 - Street Fighter (Japan)-image.jpg</image>
<rating>0.7</rating>
<releasedate>19900808T000000</releasedate>
<developer>Capcom</developer>
<publisher>Capcom</publisher>
<genre>Fighting</genre>
<region>Japan</region>
<romtype>Original</romtype>
</game>
"""