Before embarking on CMOR4, it might be useful to look at some python code written elsewhere:
https://pymorize.readthedocs.io/en/latest/pymorize_cli.html
I have no idea whether this attempts to do what we want to do, but we might be able to get some help with writing CMOR4 from some of the authors of pymorize.