Mercurial > piecrust2
changeset 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 | cedefb806bfd |
children | 371731b555ec |
files | piecrust/app.py piecrust/main.py |
diffstat | 2 files changed, 19 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/app.py Sun Jul 23 08:31:05 2017 -0700 +++ b/piecrust/app.py Sun Jul 23 18:01:26 2017 -0700 @@ -253,12 +253,13 @@ return dirs -def apply_variant_and_values(app, config_variant=None, config_values=None): - if config_variant is not None: - logger.debug("Adding configuration variant '%s'." % config_variant) - variant_path = os.path.join( - app.root_dir, 'configs', '%s.yml' % config_variant) - app.config.addVariant(variant_path) +def apply_variants_and_values(app, config_variants=None, config_values=None): + if config_variants is not None: + for value in config_variants: + logger.debug("Adding configuration variant '%s'." % value) + variant_path = os.path.join( + app.root_dir, 'configs', '%s.yml' % value) + app.config.addVariant(variant_path) if config_values is not None: for name, value in config_values: @@ -273,12 +274,12 @@ def __init__( self, root_dir, *, cache=True, cache_key=None, - config_variant=None, config_values=None, + config_variants=None, config_values=None, debug=False, theme_site=False): self.root_dir = root_dir self.cache = cache self.cache_key = cache_key - self.config_variant = config_variant + self.config_variants = config_variants self.config_values = config_values self.debug = debug self.theme_site = theme_site @@ -290,7 +291,7 @@ cache_key=self.cache_key, debug=self.debug, theme_site=self.theme_site) - apply_variant_and_values( - app, self.config_variant, self.config_values) + apply_variants_and_values( + app, self.config_variants, self.config_values) return app
--- a/piecrust/main.py Sun Jul 23 08:31:05 2017 -0700 +++ b/piecrust/main.py Sun Jul 23 18:01:26 2017 -0700 @@ -91,8 +91,9 @@ help="Makes the current command apply to a theme website.") parser.add_argument( '--config', - dest='config_variant', - help="The configuration variant to use for this command.") + action='append', + dest='config_variants', + help="The configuration variant(s) to use for this command.") parser.add_argument( '--config-set', nargs=2, @@ -209,8 +210,9 @@ cmd_name = pre_args.extra_args[0] if cmd_name in _command_caches: cache_key_str = _command_caches[cmd_name] - if pre_args.config_variant is not None: - cache_key_str += ',variant=%s' % pre_args.config_variant + if pre_args.config_variants: + for value in pre_args.config_variants: + cache_key_str += ',variant=%s' % value if pre_args.config_values: for name, value in pre_args.config_values: cache_key_str += ',%s=%s' % (name, value) @@ -233,7 +235,7 @@ root = None # Can't apply custom configuration stuff if there's no website. - if (pre_args.config_variant or pre_args.config_values) and not root: + if (pre_args.config_variants or pre_args.config_values) and not root: raise SiteNotFoundError( "Can't apply any configuration variant or value overrides, " "there is no website here.") @@ -248,7 +250,7 @@ cache=(not pre_args.no_cache), cache_key=cache_key, debug=pre_args.debug, - config_variant=pre_args.config_variant, + config_variants=pre_args.config_variants, config_values=pre_args.config_values) app = appfactory.create() else: