comparison piecrust/app.py @ 909:eed19a80c00e

chef: Allow multiple config variants to be applied.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 23 Jul 2017 18:01:26 -0700
parents cc2647360036
children 8adc27285d93
comparison
equal deleted inserted replaced
908:cedefb806bfd 909:eed19a80c00e
251 dirs.append(default_dir) 251 dirs.append(default_dir)
252 252
253 return dirs 253 return dirs
254 254
255 255
256 def apply_variant_and_values(app, config_variant=None, config_values=None): 256 def apply_variants_and_values(app, config_variants=None, config_values=None):
257 if config_variant is not None: 257 if config_variants is not None:
258 logger.debug("Adding configuration variant '%s'." % config_variant) 258 for value in config_variants:
259 variant_path = os.path.join( 259 logger.debug("Adding configuration variant '%s'." % value)
260 app.root_dir, 'configs', '%s.yml' % config_variant) 260 variant_path = os.path.join(
261 app.config.addVariant(variant_path) 261 app.root_dir, 'configs', '%s.yml' % value)
262 app.config.addVariant(variant_path)
262 263
263 if config_values is not None: 264 if config_values is not None:
264 for name, value in config_values: 265 for name, value in config_values:
265 logger.debug("Adding configuration override '%s': %s" % 266 logger.debug("Adding configuration override '%s': %s" %
266 (name, value)) 267 (name, value))
271 """ A class that builds a PieCrust app instance. 272 """ A class that builds a PieCrust app instance.
272 """ 273 """
273 def __init__( 274 def __init__(
274 self, root_dir, *, 275 self, root_dir, *,
275 cache=True, cache_key=None, 276 cache=True, cache_key=None,
276 config_variant=None, config_values=None, 277 config_variants=None, config_values=None,
277 debug=False, theme_site=False): 278 debug=False, theme_site=False):
278 self.root_dir = root_dir 279 self.root_dir = root_dir
279 self.cache = cache 280 self.cache = cache
280 self.cache_key = cache_key 281 self.cache_key = cache_key
281 self.config_variant = config_variant 282 self.config_variants = config_variants
282 self.config_values = config_values 283 self.config_values = config_values
283 self.debug = debug 284 self.debug = debug
284 self.theme_site = theme_site 285 self.theme_site = theme_site
285 286
286 def create(self): 287 def create(self):
288 self.root_dir, 289 self.root_dir,
289 cache=self.cache, 290 cache=self.cache,
290 cache_key=self.cache_key, 291 cache_key=self.cache_key,
291 debug=self.debug, 292 debug=self.debug,
292 theme_site=self.theme_site) 293 theme_site=self.theme_site)
293 apply_variant_and_values( 294 apply_variants_and_values(
294 app, self.config_variant, self.config_values) 295 app, self.config_variants, self.config_values)
295 return app 296 return app
296 297