Mercurial > piecrust2
annotate piecrust/commands/builtin/publishing.py @ 886:dcdec4b951a1
admin: Get the admin panel working again.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Jun 2017 21:13:08 -0700 |
parents | 13e8b50a2113 |
children | d709429f02eb |
rev | line source |
---|---|
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import logging |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from piecrust.commands.base import ChefCommand |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 logger = logging.getLogger(__name__) |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 class PublishCommand(ChefCommand): |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 """ Command for running publish targets for the current site. |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 """ |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 def __init__(self): |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 super(PublishCommand, self).__init__() |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 self.name = 'publish' |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 self.description = "Publishes you website to a specific target." |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 def setupParser(self, parser, app): |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 parser.add_argument( |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
18 '--log-publisher', |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
19 metavar='LOG_FILE', |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
20 help="Log the publisher's output to a given file.") |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 parser.add_argument( |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
22 '--preview', |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
23 action='store_true', |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
24 help="Only preview what the publisher would do.") |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
781
71a755512eb8
chef: Don't crash when running `chef` outside of a website.
Ludovic Chabant <ludovic@chabant.com>
parents:
758
diff
changeset
|
26 # Don't setup anything for a null app. |
71a755512eb8
chef: Don't crash when running `chef` outside of a website.
Ludovic Chabant <ludovic@chabant.com>
parents:
758
diff
changeset
|
27 if app.root_dir is None: |
71a755512eb8
chef: Don't crash when running `chef` outside of a website.
Ludovic Chabant <ludovic@chabant.com>
parents:
758
diff
changeset
|
28 return |
71a755512eb8
chef: Don't crash when running `chef` outside of a website.
Ludovic Chabant <ludovic@chabant.com>
parents:
758
diff
changeset
|
29 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
30 subparsers = parser.add_subparsers() |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
31 for pub in app.publishers: |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
32 p = subparsers.add_parser( |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
33 pub.target, |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
34 help="Publish using target '%s'." % pub.target) |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
35 pub.setupPublishParser(p, app) |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
36 p.set_defaults(sub_func=self._doPublish) |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
37 p.set_defaults(target=pub.target) |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
39 if not app.publishers: |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
40 parser.epilog = ( |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
41 "No publishers have been defined. You can define publishers " |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
42 "through the `publish` configuration settings. " |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
43 "For more information see: " |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
44 "https://bolt80.com/piecrust/en/latest/docs/publishing/") |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
45 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
46 def checkedRun(self, ctx): |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
47 from piecrust.pathutil import SiteNotFoundError |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
48 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
49 if ctx.app.root_dir is None: |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
50 raise SiteNotFoundError(theme=ctx.app.theme_site) |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
51 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
52 if not hasattr(ctx.args, 'sub_func'): |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
53 ctx.parser.parse_args(['publish', '--help']) |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 return |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
55 ctx.args.sub_func(ctx) |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
57 def _doPublish(self, ctx): |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
58 from piecrust.publishing.base import PublishingManager |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
59 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
60 pub = PublishingManager(ctx.appfactory, ctx.app) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
61 pub.run( |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
62 ctx.args.target, |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
63 preview=ctx.args.preview, |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
781
diff
changeset
|
64 extra_args=ctx.args, |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
65 log_file=ctx.args.log_publisher) |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 |