Manipulating Datamodels

Here we describe special cases for interacting with and manipulating datamodels after they have been generated.

Removing Releases

Sometimes it may be necessary to remove a release from a datamodel. The easiest way to remove a release from a datamodel YAML file is with the datamodel remove cli. You can also do it in Python albeit in a slightly more complicated manner.

Remove a release from a datamodel using the command-line:

$ datamodel remove -f astraAllStarAPOGEENet -r IPL2

From within Python, you need to explicitly remove the release and call to re-write the other datamodel files.

from datamodel.generate import DataModel

# get the datamodel
fs = "astraAllStarAPOGEENet"
dm = DataModel.from_yaml(fs, release="IPL2")

# remove the IPL-2 release from the YAML stub
s = dm.get_stub("yaml")
s.remove_release("IPL2")
s.write()

# re-write the JSON, md and access files
dm = DataModel.from_yaml(fs, release="IPL1")
dm.write_stubs()