Initializing the Template
Step 1 - Initializing the Custom Template
We will now initialize the custom template we created in the previous page.
Open the terminal to an empty folder and run:
uip init -t <path to example_template.zip> -e "log_level=WaRn"
The command should run successfully with the following output:
Successfully initialized "example-template (1.0.0)" template in "<path may vary>"
The directory structure (ignoring *.pyc and __pycache__) should be as follows:
<folder name>/
├── .uip
│ └── config
│ └── uip.yml
├── __init__.py
├── requirements.txt
├── setup.cfg
├── setup.py
└── src
├── __init__.py
├── extension.py
├── extension.yml
└── templates
└── template.json
At this point, we have successfully initialized the custom template with the custom parameters, log_level and msg.
Open src/extension.py, and you should see my_msg on line 19 set to "test_message". Since a value for the msg variable wasn’t specified during initialization time, the default value (defined in template_config.yml) of test_message was substituted.
Open src/templates/template.json, and you should see the logLevel property set to Warn as expected.
Step 2 - Saving the Template using uip init
In the previous step, we initialized an Extension using the example_template.zip. If we want to do that again, the zip file will need to be specified again as well.
There are two ways to save the example_template for future use, and the first one is shown below:
Go ahead and delete the Extension initialized in the folder, including the .uip/ folder. Assuming it’s an empty folder, run
uip init -t <path to example_template.zip> -e "log_level=WaRn" -e "msg=sample message!" --save
Specifying --save will save the template in a location known to the CLI. If you now run
uip template list
you should see the example-template listed as well for future use
+--------------------+---------+---------------------------------------------------------+
| Extension Template | Version | Description |
+--------------------+---------+---------------------------------------------------------+
| ue-task | 1.0.0 | starter Extension with minimal code |
+--------------------+---------+---------------------------------------------------------+
| ue-publisher | 1.0.0 | starter Extension with a local Universal Event template |
+--------------------+---------+---------------------------------------------------------+
| example-template | 1.0.0 | this is the description for example template |
+--------------------+---------+---------------------------------------------------------+
The value of name, version, and description from template_config.yml are used to populate the table entry for example-template
To see the variables we defined in template_config.yml, run
uip template list example-template
which will print
+---------------+--------------+---------------------------------------+
| Variable Name | Default | Description |
+---------------+--------------+---------------------------------------+
| msg | test_message | message to print to STDOUT and STDERR |
| log_level | Info | Universal Template Log Level |
+---------------+--------------+---------------------------------------+
Go ahead and delete the previously initialized Extension once again, including the .uip/ folder. Assuming it’s an empty folder, run
uip init -t example-template -e "log_level=WaRn" -e "msg=sample message!"
Notice that the path to the zip file no longer needs to be specified, since the template has already been saved.