Mercurial > piecrust2
view 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 source
import logging import urllib.parse from piecrust.commands.base import ChefCommand from piecrust.publishing.publisher import Publisher, find_publisher_name logger = logging.getLogger(__name__) class PublishCommand(ChefCommand): """ Command for running publish targets for the current site. """ def __init__(self): super(PublishCommand, self).__init__() self.name = 'publish' self.description = "Publishes you website to a specific target." def setupParser(self, parser, app): parser.add_argument( '-l', '--list', action='store_true', help="List available publish targets for the current site.") parser.add_argument( '--log-publisher', 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', help="The publish target to use.") def run(self, ctx): if ctx.args.list: pub_cfg = ctx.app.config.get('publish') if not pub_cfg: logger.info("No available publish targets.") return for name, cfg in pub_cfg.items(): 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.error( "%s (incorrect configuration)" % name) return pub = Publisher(ctx.app) pub.run( ctx.args.target, preview=ctx.args.preview, log_file=ctx.args.log_publisher)