Mercurial > piecrust2
diff piecrust/commands/builtin/publishing.py @ 621:8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
* Add a `--preview` option.
* The `--list` option gives a nicer output, and prints warnings/errors for
incorrect configuration.
* Moved most of the `shell` code into a base class that's reusable.
* Simplified the code to log publishing to a file.
* Nicer output overall, with times.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 08 Feb 2016 20:44:26 -0800 |
parents | e2e955a3bb25 |
children | 6abb436fea5b |
line wrap: on
line diff
--- a/piecrust/commands/builtin/publishing.py Sat Feb 06 21:49:50 2016 -0800 +++ b/piecrust/commands/builtin/publishing.py Mon Feb 08 20:44:26 2016 -0800 @@ -1,6 +1,7 @@ import logging +import urllib.parse from piecrust.commands.base import ChefCommand -from piecrust.publishing.publisher import Publisher +from piecrust.publishing.publisher import Publisher, find_publisher_name logger = logging.getLogger(__name__) @@ -24,6 +25,10 @@ metavar='LOG_FILE', help="Log the publisher's output to a given file.") parser.add_argument( + '--preview', + action='store_true', + help="Only preview what the publisher would do.") + parser.add_argument( 'target', nargs='?', default='default', @@ -37,13 +42,37 @@ return for name, cfg in pub_cfg.items(): - desc = cfg.get('description') - if not desc: - logger.info(name) + if isinstance(cfg, dict): + pub_type = cfg.get('type') + if pub_type: + desc = cfg.get('description') + bake_first = cfg.get('bake', True) + msg = '%s (%s)' % (name, pub_type) + if not bake_first: + msg += ' (no local baking)' + if desc: + msg += ': ' + desc + logger.info(msg) + else: + logger.error( + "%s (unknown type '%s')" % (name, pub_type)) + elif isinstance(cfg, str): + comps = urllib.parse.urlparse(str(cfg)) + pub_name = find_publisher_name(ctx.app, comps.scheme) + if pub_name: + logger.info("%s (%s)" % (name, pub_name)) + else: + logger.error( + "%s (unknown scheme '%s')" % + (name, comps.scheme)) else: - logger.info("%s: %s" % (name, desc)) + logger.error( + "%s (incorrect configuration)" % name) return pub = Publisher(ctx.app) - pub.run(ctx.args.target, log_file=ctx.args.log_publisher) + pub.run( + ctx.args.target, + preview=ctx.args.preview, + log_file=ctx.args.log_publisher)