src/platform/python/tests/cinema/gb/mooneye-gb/update.py (view raw)
1#!/usr/bin/env python
2import os
3import os.path
4import shutil
5import yaml
6from cinema.util import dictMerge
7
8suffixes = {
9 'C': 'CGB',
10 'S': 'SGB',
11 'A': 'AGB',
12 'mgb': 'MGB',
13 'sgb': 'SGB',
14 'sgb2': 'SGB2',
15 'cgb': 'CGB',
16 'agb': 'AGB',
17 'ags': 'AGB',
18}
19
20def ingestDirectory(path, dest):
21 for root, _, files in os.walk(path, topdown=False):
22 root = root[len(os.path.commonprefix([root, path])):]
23 if root.startswith('utils'):
24 continue
25 for file in files:
26 fname, ext = os.path.splitext(file)
27 if ext not in ('.gb', '.sym'):
28 continue
29
30 try:
31 os.makedirs(os.path.join(dest, root, fname))
32 except OSError:
33 pass
34
35 if ext in ('.gb', '.sym'):
36 shutil.copy(os.path.join(path, root, file), os.path.join(dest, root, fname, 'test' + ext))
37
38 for suffix, model in suffixes.items():
39 if fname.endswith('-' + suffix):
40 manifest = {}
41 try:
42 with open(os.path.join(dest, root, fname, 'manifest.yml'), 'r') as f:
43 manifest = yaml.safe_load(f) or {}
44 except FileNotFoundError:
45 pass
46 dictMerge(manifest, {
47 'config': {
48 'gb.model': model
49 }
50 })
51 with open(os.path.join(dest, root, fname, 'manifest.yml'), 'w') as f:
52 yaml.dump(manifest, f)
53
54if __name__ == '__main__':
55 import argparse
56 parser = argparse.ArgumentParser(description='Update mooneye-gb test suite')
57 parser.add_argument('source', type=str, help='directory containing built tests')
58 parser.add_argument('dest', type=str, nargs='?', default=os.path.dirname(__file__), help='directory to contain ingested tests')
59 args = parser.parse_args()
60
61 ingestDirectory(args.source, args.dest)