Mercurial > piecrust2
diff piecrust/commands/builtin/publishing.py @ 613:e2e955a3bb25
publish: Add publish command.
* Add `shell` publisher.
* Refactor admin panel's publishing backend to use that, along with the new
PID file support.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 04 Feb 2016 08:05:03 -0800 |
parents | |
children | 8f9c0bdb3724 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/piecrust/commands/builtin/publishing.py Thu Feb 04 08:05:03 2016 -0800 @@ -0,0 +1,49 @@ +import logging +from piecrust.commands.base import ChefCommand +from piecrust.publishing.publisher import Publisher + + +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( + '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(): + desc = cfg.get('description') + if not desc: + logger.info(name) + else: + logger.info("%s: %s" % (name, desc)) + return + + pub = Publisher(ctx.app) + pub.run(ctx.args.target, log_file=ctx.args.log_publisher) +