Jagadeesh N M Jagadeesh N M - 2 years ago 75
Python Question

Adding value dynamically in buildout configuration

I am looking for populating value, in zc.buildout configuration, by evaluating certain criteria. For example,

if fqdn endswith '.net'
hostname = this_pkg_server
hostname = that_pkg_server

I am looking to build site specific configuration. I can evaluate fqdn with macro but how to populate that value in configuration?


Answer Source

The simplest answer is to use the wonderful mr.scripty.

Page on PyPI:

Untested example:

parts =

    ... import os
    ... if os.environ.get('HOSTNAME', '').endswith('.net'):
    ...     return 'this_pkg_server'
    ... return 'that_pkg_server'

You can then use across your buildout the returned value as ${hostname:pkg_server}.

There is a more complex solution, i.e. writing your own buildout recipe. It is not that easy, but the effort may not be worth the task.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download