04.06.2013 Views

UCS 2.4 - Univention

UCS 2.4 - Univention

UCS 2.4 - Univention

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

closed with the string @!@.<br />

14.12 Integrating Python code<br />

In the following example the template /etc/univention/templates/files/etc/issue (from which<br />

the /etc/issue file is created) is expanded with Python code. Before it looks like this:<br />

@!@<br />

if baseConfig[’version/version’] and baseConfig[’version/patchlevel’]:<br />

print ’<strong>UCS</strong> \%s-\%s \BS\BSn \BS\BSl’ \% \<br />

(baseConfig[’version/version’], \<br />

baseConfig[’version/patchlevel’])<br />

@!@<br />

If the value of a <strong>Univention</strong> Configuration Registry variable should be queried in Python code, the baseC-<br />

onfig Python object can be used as shown in the example. When using Python code it is important to note<br />

that the variables used in the Python code are specified when creating the package (see Chapter 14.10).<br />

Two <strong>Univention</strong> Configuration Registry variables, hostname and domainname, are now added outside of<br />

the Python code, while the /etc/univention/templates/files/etc/issue template is edited as<br />

follows:<br />

@!@<br />

if baseConfig[’version/version’] and baseConfig[’version/patchlevel’]:<br />

print ’<strong>UCS</strong> \%s-\%s \BS\BSn \BS\BSl’ \% \<br />

(baseConfig[’version/version’], \<br />

baseConfig[’version/patchlevel’])<br />

@!@<br />

The host name is: @%@hostname@%@<br />

The domain name is: @%@domainname@%@<br />

The /etc/issue file can now be regenerated from its template using the following command:<br />

univention-config-registry commit /etc/issue<br />

If new variables are introduced, it is important to follow the naming scheme (see Chapter 14.5). The<br />

following example introduces two new variables, my/variable1 and my/variable2:<br />

@!@<br />

if baseConfig[’version/version’] and baseConfig[’version/patchlevel’]:<br />

print ’<strong>UCS</strong> \%s-\%s \BS\BSn \BS\BSl’ \% \<br />

(baseConfig[’version/version’], \<br />

baseConfig[’version/patchlevel’])<br />

@!@<br />

My first variable: @%@my/variable1@%@<br />

My second variable: @%@my/variable2@%@<br />

To fill the new variables defined in inline Python code with values, the cache file must be deleted once from<br />

<strong>Univention</strong> Configuration Registry.<br />

rm /var/cache/univention-config/cache<br />

The new variables can then be set as described in Chapter 14.5.<br />

univention-config-registry set my/variable1="foo" set my/variable2="bar"<br />

The /etc/issue file is now regenerated from its template.<br />

287

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!