6

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

if fqdn endswith '.net' then hostname = this_pkg_server else 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?

Thanks

SteveM
  • 6,058
  • 1
  • 16
  • 20
Jagadeesh N M
  • 625
  • 1
  • 5
  • 9

1 Answers1

7

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

Page on PyPI:

Untested example:

[buildout]
parts =
    hostname 

[hostname]
recipe=mr.scripty
pkg_server=
    ... 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.

alepisa
  • 1,324
  • 8
  • 14
  • 1
    Thanks for showing me this option. I was reading through manual and got conditional section. That too helped me for now. But for sure your solution is better one. – Jagadeesh N M May 03 '16 at 06:28
  • 1
    You are welcome :) And thanks to you because you pointed me to conditional sections, whose existence I did not know! – alepisa May 03 '16 at 14:04