all repos — mgba @ a1c61edf5c161825458d7da2245b94a7f98b9bae

mGBA Game Boy Advance Emulator

cinema/gb/mooneye-gb/update.py (view raw)

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