Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
612:2edaefcb82cd | 613:e2e955a3bb25 |
---|---|
1 import logging | |
2 from piecrust.commands.base import ChefCommand | |
3 from piecrust.publishing.publisher import Publisher | |
4 | |
5 | |
6 logger = logging.getLogger(__name__) | |
7 | |
8 | |
9 class PublishCommand(ChefCommand): | |
10 """ Command for running publish targets for the current site. | |
11 """ | |
12 def __init__(self): | |
13 super(PublishCommand, self).__init__() | |
14 self.name = 'publish' | |
15 self.description = "Publishes you website to a specific target." | |
16 | |
17 def setupParser(self, parser, app): | |
18 parser.add_argument( | |
19 '-l', '--list', | |
20 action='store_true', | |
21 help="List available publish targets for the current site.") | |
22 parser.add_argument( | |
23 '--log-publisher', | |
24 metavar='LOG_FILE', | |
25 help="Log the publisher's output to a given file.") | |
26 parser.add_argument( | |
27 'target', | |
28 nargs='?', | |
29 default='default', | |
30 help="The publish target to use.") | |
31 | |
32 def run(self, ctx): | |
33 if ctx.args.list: | |
34 pub_cfg = ctx.app.config.get('publish') | |
35 if not pub_cfg: | |
36 logger.info("No available publish targets.") | |
37 return | |
38 | |
39 for name, cfg in pub_cfg.items(): | |
40 desc = cfg.get('description') | |
41 if not desc: | |
42 logger.info(name) | |
43 else: | |
44 logger.info("%s: %s" % (name, desc)) | |
45 return | |
46 | |
47 pub = Publisher(ctx.app) | |
48 pub.run(ctx.args.target, log_file=ctx.args.log_publisher) | |
49 |