From a190afc94966c53a353b28d9e4d30a3583e4bced Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Fri, 3 Oct 2014 11:33:21 +0200 Subject: utils_prog: getenv_namespaced for accessing CLUFTER_X env vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Actually, the namespace is derived from the package name directly. Signed-off-by: Jan Pokorný --- utils_prog.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'utils_prog.py') diff --git a/utils_prog.py b/utils_prog.py index b286220..82c4c69 100644 --- a/utils_prog.py +++ b/utils_prog.py @@ -16,6 +16,7 @@ from os.path import abspath, dirname, samefile, \ from subprocess import Popen from sys import stderr, stdin +from . import package_name from .error import ClufterError from .utils import areinstances, \ filterdict_pop, \ @@ -274,3 +275,8 @@ def defer_common(me, fnc, skip=0): return fnc(cmd_ctxt, **kwargs) wrapfnc.__doc__ = fnc.__doc__ + common.__doc__ return fnc_defaults, fnc_varnames, wrapfnc + + +def getenv_namespaced(varname, value=None, namespace=package_name().upper()): + """Obtain value of environment variable prefixed with `namespace + '_'`""" + return environ.get('_'.join((namespace, varname)), value) -- cgit