comparison piecrust/main.py @ 1129:957f7c972715

chef: Support special tokens in the `chef/env` setting.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 28 Feb 2018 20:43:52 -0800
parents 40228511d600
children
comparison
equal deleted inserted replaced
1128:6ab1299c1058 1129:957f7c972715
244 logger.debug("Using cache key: %s" % cache_key_str) 244 logger.debug("Using cache key: %s" % cache_key_str)
245 cache_key = hashlib.md5(cache_key_str.encode('utf8')).hexdigest() 245 cache_key = hashlib.md5(cache_key_str.encode('utf8')).hexdigest()
246 return cache_key 246 return cache_key
247 247
248 248
249 def _setup_app_environment(env): 249 def _setup_app_environment(app, env):
250 from piecrust.uriutil import multi_replace
251
252 tokens = {
253 '%root_dir%': app.root_dir}
254
250 for k, v in env.items(): 255 for k, v in env.items():
251 varname = k 256 varname = k
252 append = False 257 append = False
253 if k.lower() == 'path': 258 if k.lower() == 'path':
254 append = True 259 append = True
255 v = os.pathsep + v 260 v = os.pathsep + v
256 elif k.endswith('+'): 261 elif k.endswith('+'):
257 varname = k[:-1] 262 varname = k[:-1]
258 append = True 263 append = True
264
265 v = multi_replace(v, tokens)
259 266
260 if append: 267 if append:
261 logger.debug("Env: $%s += %s" % (varname, v)) 268 logger.debug("Env: $%s += %s" % (varname, v))
262 os.environ[varname] += v 269 os.environ[varname] += v
263 else: 270 else:
335 return 0 342 return 0
336 343
337 # Do any custom setup the user wants. 344 # Do any custom setup the user wants.
338 custom_env = app.config.get('chef/env') 345 custom_env = app.config.get('chef/env')
339 if custom_env: 346 if custom_env:
340 _setup_app_environment(custom_env) 347 _setup_app_environment(app, custom_env)
341 348
342 # Add some timing information. 349 # Add some timing information.
343 if app.env: 350 if app.env:
344 app.env.stats.registerTimer('ChefStartup') 351 app.env.stats.registerTimer('ChefStartup')
345 app.env.stats.stepTimerSince('ChefStartup', _chef_start_time) 352 app.env.stats.stepTimerSince('ChefStartup', _chef_start_time)