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

62 lines
2.0 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
import yaml
2019-07-06 22:21:04 +00:00
from cinema.util import dict_merge
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):
manifest = {}
try:
with open(os.path.join(dest, root, fname, 'manifest.yml'), 'r') as f:
manifest = yaml.safe_load(f) or {}
2017-08-13 23:00:42 +00:00
except IOError:
2017-08-13 01:10:05 +00:00
pass
2019-07-06 22:21:04 +00:00
dict_merge(manifest, {
2017-08-13 01:10:05 +00:00
'config': {
'gb.model': model
}
})
with open(os.path.join(dest, root, fname, 'manifest.yml'), 'w') as f:
yaml.dump(manifest, f)
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)