Mercurial > piecrust2
diff piecrust/main.py @ 1116:40228511d600
chef: Add new `chef/env` config section.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 25 Feb 2018 21:48:55 -0800 |
parents | c4cfbbeed72e |
children | 957f7c972715 |
line wrap: on
line diff
--- a/piecrust/main.py Sat Feb 24 21:13:54 2018 -0800 +++ b/piecrust/main.py Sun Feb 25 21:48:55 2018 -0800 @@ -246,6 +246,25 @@ return cache_key +def _setup_app_environment(env): + for k, v in env.items(): + varname = k + append = False + if k.lower() == 'path': + append = True + v = os.pathsep + v + elif k.endswith('+'): + varname = k[:-1] + append = True + + if append: + logger.debug("Env: $%s += %s" % (varname, v)) + os.environ[varname] += v + else: + logger.debug("Env: $%s = %s" % (varname, v)) + os.environ[varname] = v + + def _run_chef(pre_args, argv): # Setup the app. root = None @@ -315,6 +334,11 @@ parser.print_help() return 0 + # Do any custom setup the user wants. + custom_env = app.config.get('chef/env') + if custom_env: + _setup_app_environment(custom_env) + # Add some timing information. if app.env: app.env.stats.registerTimer('ChefStartup')