comparison 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
comparison
equal deleted inserted replaced
1115:11b9d0c8bd62 1116:40228511d600
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):
250 for k, v in env.items():
251 varname = k
252 append = False
253 if k.lower() == 'path':
254 append = True
255 v = os.pathsep + v
256 elif k.endswith('+'):
257 varname = k[:-1]
258 append = True
259
260 if append:
261 logger.debug("Env: $%s += %s" % (varname, v))
262 os.environ[varname] += v
263 else:
264 logger.debug("Env: $%s = %s" % (varname, v))
265 os.environ[varname] = v
266
267
249 def _run_chef(pre_args, argv): 268 def _run_chef(pre_args, argv):
250 # Setup the app. 269 # Setup the app.
251 root = None 270 root = None
252 if pre_args.root: 271 if pre_args.root:
253 root = os.path.expanduser(pre_args.root) 272 root = os.path.expanduser(pre_args.root)
313 # Print the help if no command was specified. 332 # Print the help if no command was specified.
314 if not hasattr(result, 'func'): 333 if not hasattr(result, 'func'):
315 parser.print_help() 334 parser.print_help()
316 return 0 335 return 0
317 336
337 # Do any custom setup the user wants.
338 custom_env = app.config.get('chef/env')
339 if custom_env:
340 _setup_app_environment(custom_env)
341
318 # Add some timing information. 342 # Add some timing information.
319 if app.env: 343 if app.env:
320 app.env.stats.registerTimer('ChefStartup') 344 app.env.stats.registerTimer('ChefStartup')
321 app.env.stats.stepTimerSince('ChefStartup', _chef_start_time) 345 app.env.stats.stepTimerSince('ChefStartup', _chef_start_time)
322 346