Toaster custom data: Difference between revisions

From Yocto Project
Jump to navigationJump to search
Line 18: Line 18:


To add custom initial data/configuration to Toaster place a file called
To add custom initial data/configuration to Toaster place a file called
"custom.xml" in this directory. If present it will be loaded into the database.
"custom.xml" in bitbake/lib/toaster/orm/fixtures/ directory. If present it will be loaded into the database on start up, last.
We suggest that this is used to overlay any configuration already done.
We suggest that this is used to overlay any configuration already done.
All objects loaded with the same primary keys overwrite the existing data.
All objects loaded with the same primary keys overwrite the existing data.

Revision as of 13:46, 23 November 2016

When Toaster is first started up it uses Django fixtures to populate some initial data into it's database. Once this is done we then connect to the openembedded layer index and download information about various metadata that is available for the configured releases.

Fixtures directory lib/toaster/orm/fixtures

Fixtures are data dumps that can be loaded into Toaster's database to provide configuration and data.

In this directory we have the fixtures which are loaded the first time you start Toaster. This is to provide useful default values and metadata to Toaster.

  • settings.xml This Contains Toaster wide settings, such as the default values for certain bitbake variables.
  • poky.xml This is the default release data for supported poky based setup
  • oe-core.xml This is the default release data for supported oe-core based setups

Custom data/configuration

  • custom.xml

To add custom initial data/configuration to Toaster place a file called "custom.xml" in bitbake/lib/toaster/orm/fixtures/ directory. If present it will be loaded into the database on start up, last. We suggest that this is used to overlay any configuration already done. All objects loaded with the same primary keys overwrite the existing data. Data can be provided in XML, JSON and if installed YAML formats.

To understand the requirements of the schema and the field names and default values see their definitions in:

  • bitbake/lib/toaster/orm/models.py
  • bitbake/lib/toaster/bldcontrol/models.py
  • Toaster database

Note that specifying primary keys are optional. The default behaviour is to replace any data which has the same primary key, this is useful if you wish to override data that is already being set use the same primary key. When there are relationships between different objects such as Many-to-One it is important to have the primary key set on the objects in the relationship so that this can be defined. E.g. A Layer object has many Layer Versions objects so to create this relationship a Layer needs a primary key specified and a Layer Version needs to specify that it 'belongs' to that Layer via the layer field .e.g

 <field rel="ManyToOneRel" to="orm.layer" name="layer">10</field>

More information about django fixtures can be found at https://docs.djangoproject.com/en/1.8/howto/initial-data/

To load data at any point in time

Use the django management command

 manage.py loaddata <your fixture file>

For further information see the Django command documentation at: https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-loaddata

Examples

Examples given in xml format for increased verbosity.

  • custom.xml

Override default package for projects

<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">

  <object model="orm.toastersetting" pk="3">
    <field type="CharField" name="name">DEFCONF_PACKAGE_CLASSES</field>
    <field type="CharField" name="value">package_ipk</field>
  </object>

</django-objects>

Add a default layer from a git source

<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">

  <object model="orm.layer" pk="10">
    <field type="CharField" name="name">meta-my-layer</field>
    <field type="CharField" name="layer_index_url"></field>
    <field type="CharField" name="vcs_url">git://git.example.com/my_repo</field>
  </object>
  <object model="orm.layer_version" pk="13">
    <field rel="ManyToOneRel" to="orm.layer" name="layer">10</field>
    <field type="IntegerField" name="layer_source">0</field>
    <field rel="ManyToOneRel" to="orm.release" name="release">1</field>
    <field type="CharField" name="branch">v1.2.3</field>
    <field type="CharField" name="dirpath">layers/meta-my-layer</field>
  </object>

  <object model="orm.releasedefaultlayer" pk="15">
    <field rel="ManyToOneRel" to="orm.release" name="release">3</field>
    <field type="CharField" name="layer_name">meta-my-layer</field>
  </object>
</django-objects>

Add an available layer from a local file system source

<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">

  <object model="orm.layer" pk="20">
    <field type="CharField" name="name">meta-my-layer</field>
    <field type="CharField" name="layer_index_url"></field>
    <field type="CharField" name="local_source_dir">/home/developer/work/meta-my-layer</field>
  </object>
  <object model="orm.layer_version" pk="13">
    <field rel="ManyToOneRel" to="orm.layer" name="layer">20</field>
    <field type="IntegerField" name="layer_source">0</field>
    <field rel="ManyToOneRel" to="orm.release" name="release">1</field>
  </object>

</django-objects>