[Zope-dev] [ZConfig] elementary function framework and "env" function

Dieter Maurer dieter at handshake.de
Fri Jan 16 10:46:05 EST 2004


We often have the need to use the same configuration value
both in a ZConfig configuration as well as in other non-ZConfig
based "components".

Prominent examples are the "INSTANCE_HOME" in the Zope/ZEO startup
scripts and the "INSTANCE" definition in the corresponding
configuration files.

Moreover, configuration values are sometimes arithmethically
related, but ZConfig lacks arithmetic capabilities.
An example is the ZEO port which should (under some conditions)
be derived from "PORT_BASE".

Giving "ZConfig" access to the environment, allows configuration
setup to use the arithmetic capabilities of the shell
and communicate configuation values via the environment
between "ZConfig" based components and components that use different
configuration schemes.


The attached patch gives "ZConfig" an elementary function framework.
An application can register functions with "ZConfig".
These functions can be called through "substitution".
Its syntax is similar to "gmakes" function call:

    $(f)   calls function "f" with no arguments
    $(f a1,a2,...) calls function "f" with arguments "a1", "a2", ...

  Arguments are "," separated, stripped and substitution expanded
  before they are passed to the function.
  "," can be escaped through duplication, "(" is not allowed
  in the "ai" (although they can come up after substitution).

  Functions are called with "mapping" as additional first argument
  (such that they can do fancy things; e.g. implement
  Bash's "default" interpolation ("${name:-default}").

The patch uses the framework to implement a single function
"env":

	env(name, default=None)

	returns the value of "name" in the environment
	or "default".
	If the result it "None", a "KeyError" is raised.

-- 
Dieter

-------------- next part --------------
A non-text attachment was scrubbed...
Name: zconfig_functions.pat
Type: application/x-patch
Size: 8588 bytes
Desc: ZConfig patch: elementary function framework + "env"
	function (environment access)
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20040116/bf11d787/zconfig_functions.bin


More information about the Zope-Dev mailing list