#!/usr/bin/python3 import os import os.path as path import sys from glob import glob import json olddir = os.curdir scriptdir = path.realpath(path.dirname(__file__)) os.chdir(scriptdir) outpath = path.join(sys.argv[1], "backend_glue.cpp") ui_backend_dir = path.join(scriptdir, "backends", "ui") ui_backend_metafiles = [] playback_backend_dir = path.join(scriptdir, "backends", "playback") playback_backend_metafiles = [] adding_uis = True for backend in sys.argv[2:]: if backend == "--ui": adding_uis = True continue elif backend == "--playback": adding_uis = False continue if adding_uis: ui_backend_metafiles += [ui_backend_dir + "/" + backend + "/ui.json"] else: playback_backend_metafiles += [playback_backend_dir + "/" + backend + "/backend.json"] ui_backends = [] playback_backends = [] for metafile_path in ui_backend_metafiles: with open(metafile_path, "rt") as metafile: metajson = json.load(metafile) incpath = path.join(path.dirname(metafile_path), metajson["include_path"]) incpath = path.relpath(incpath, scriptdir) ui_backend = {"class_name": metajson["class_name"], "include_path": incpath} ui_backends.append(ui_backend) for metafile_path in playback_backend_metafiles: with open(metafile_path, "rt") as metafile: metajson = json.load(metafile) incpath = path.join(path.dirname(metafile_path), metajson["include_path"]) incpath = path.relpath(incpath, scriptdir) playback_backend = {"class_name": metajson["class_name"], "include_path": incpath} playback_backends.append(playback_backend) with open(outpath, "wt+") as of: of.write("#include \"playback_backend.hpp\"\n") of.write("#include \"backend.hpp\"\n") for ui_backend in ui_backends: of.write("#include \"%s\"\n" % ui_backend["include_path"]) for playback_backend in playback_backends: of.write("#include \"%s\"\n" % playback_backend["include_path"]) of.write(""" void init_backends() { """) for ui_backend in ui_backends: of.write("\tUIBackend::register_backend<%s>();\n" % ui_backend["class_name"]) of.write("}\n") of.write(""" void init_playback_backends() { """) for playback_backend in playback_backends: of.write("\tPlaybackBackend::register_backend<%s>();\n" % playback_backend["class_name"]) of.write("}\n") os.chdir(olddir)