mgba/cinema/gb/mooneye-gb/update.py

57 lines
1.9 KiB
Python
Raw Normal View History

2017-08-13 01:10:05 +00:00
#!/usr/bin/env python
import os
import os.path
import shutil
2020-06-17 02:13:57 +00:00
from configparser import ConfigParser
2017-08-13 01:10:05 +00:00
suffixes = {
'C': 'CGB',
'S': 'SGB',
'A': 'AGB',
'mgb': 'MGB',
'sgb': 'SGB',
'sgb2': 'SGB2',
'cgb': 'CGB',
'agb': 'AGB',
'ags': 'AGB',
}
def ingestDirectory(path, dest):
for root, _, files in os.walk(path, topdown=False):
root = root[len(os.path.commonprefix([root, path])):]
if root.startswith('utils'):
continue
for file in files:
fname, ext = os.path.splitext(file)
if ext not in ('.gb', '.sym'):
continue
try:
os.makedirs(os.path.join(dest, root, fname))
except OSError:
pass
if ext in ('.gb', '.sym'):
shutil.copy(os.path.join(path, root, file), os.path.join(dest, root, fname, 'test' + ext))
for suffix, model in suffixes.items():
if fname.endswith('-' + suffix):
2020-06-17 02:13:57 +00:00
manifest = ConfigParser()
2017-08-13 01:10:05 +00:00
try:
2020-06-17 02:13:57 +00:00
with open(os.path.join(dest, root, fname, 'config.ini'), 'r') as f:
manifest.read_file(f)
2017-08-13 23:00:42 +00:00
except IOError:
2017-08-13 01:10:05 +00:00
pass
2020-06-17 02:13:57 +00:00
manifest.set('ports.cinema', 'gb.model', model)
with open(os.path.join(dest, root, fname, 'config.ini'), 'w') as f:
manifest.write(f, space_around_delimiters=False)
2017-08-13 01:10:05 +00:00
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Update mooneye-gb test suite')
parser.add_argument('source', type=str, help='directory containing built tests')
parser.add_argument('dest', type=str, nargs='?', default=os.path.dirname(__file__), help='directory to contain ingested tests')
args = parser.parse_args()
ingestDirectory(args.source, args.dest)