Mercurial > hgrepos > Python > libs > ConfigMix
changeset 30:d70b58b0dfb9
A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 18 Mar 2016 09:27:14 +0100 |
| parents | 17af7a78710c |
| children | 50721b43e76c |
| files | configmix/variables.py |
| diffstat | 1 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/variables.py Fri Mar 18 09:13:06 2016 +0100 +++ b/configmix/variables.py Fri Mar 18 09:27:14 2016 +0100 @@ -28,7 +28,17 @@ return default -_varns_registry = {"ENV": _envlookup} +def _oslookup(name, default=_MARKER): + """Lookup an environment variable""" + if name == "cwd": + return native_os_str_to_text(os.getcwd()) + raise KeyError("key %r not found in the namespace" % name) + + +_varns_registry = { + "ENV": _envlookup, + "OS": _oslookup +} def lookup_varns(name): @@ -94,3 +104,13 @@ """ import passlib.utils return passlib.utils.saslprep(v) + + +@filter("normpath") +def normpath_impl(config, v): + return os.path.normpath(v) + + +@filter("abspath") +def abspath_impl(config, v): + return os.path.abspath(v)
