comparison piecrust/commands/builtin/publishing.py @ 879:58ae026b4c31

chef: Optimize startup time.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 15 Jun 2017 22:38:05 -0700
parents 71a755512eb8
children 13e8b50a2113
comparison
equal deleted inserted replaced
878:313db67cfc35 879:58ae026b4c31
1 import logging 1 import logging
2 import urllib.parse
3 from piecrust.commands.base import ChefCommand 2 from piecrust.commands.base import ChefCommand
4 from piecrust.pathutil import SiteNotFoundError
5 from piecrust.publishing.publisher import Publisher, find_publisher_name
6 3
7 4
8 logger = logging.getLogger(__name__) 5 logger = logging.getLogger(__name__)
9 6
10 7
16 self.name = 'publish' 13 self.name = 'publish'
17 self.description = "Publishes you website to a specific target." 14 self.description = "Publishes you website to a specific target."
18 15
19 def setupParser(self, parser, app): 16 def setupParser(self, parser, app):
20 parser.add_argument( 17 parser.add_argument(
21 '--log-publisher', 18 '--log-publisher',
22 metavar='LOG_FILE', 19 metavar='LOG_FILE',
23 help="Log the publisher's output to a given file.") 20 help="Log the publisher's output to a given file.")
24 parser.add_argument( 21 parser.add_argument(
25 '--preview', 22 '--preview',
26 action='store_true', 23 action='store_true',
27 help="Only preview what the publisher would do.") 24 help="Only preview what the publisher would do.")
28 25
29 # Don't setup anything for a null app. 26 # Don't setup anything for a null app.
30 if app.root_dir is None: 27 if app.root_dir is None:
31 return 28 return
32 29
33 subparsers = parser.add_subparsers() 30 subparsers = parser.add_subparsers()
34 for pub in app.publishers: 31 for pub in app.publishers:
35 p = subparsers.add_parser( 32 p = subparsers.add_parser(
36 pub.target, 33 pub.target,
37 help="Publish using target '%s'." % pub.target) 34 help="Publish using target '%s'." % pub.target)
38 pub.setupPublishParser(p, app) 35 pub.setupPublishParser(p, app)
39 p.set_defaults(sub_func=self._doPublish) 36 p.set_defaults(sub_func=self._doPublish)
40 p.set_defaults(target=pub.target) 37 p.set_defaults(target=pub.target)
41 38
42 if not app.publishers: 39 if not app.publishers:
45 "through the `publish` configuration settings. " 42 "through the `publish` configuration settings. "
46 "For more information see: " 43 "For more information see: "
47 "https://bolt80.com/piecrust/en/latest/docs/publishing/") 44 "https://bolt80.com/piecrust/en/latest/docs/publishing/")
48 45
49 def checkedRun(self, ctx): 46 def checkedRun(self, ctx):
47 from piecrust.pathutil import SiteNotFoundError
48
50 if ctx.app.root_dir is None: 49 if ctx.app.root_dir is None:
51 raise SiteNotFoundError(theme=ctx.app.theme_site) 50 raise SiteNotFoundError(theme=ctx.app.theme_site)
52 51
53 if not hasattr(ctx.args, 'sub_func'): 52 if not hasattr(ctx.args, 'sub_func'):
54 ctx.parser.parse_args(['publish', '--help']) 53 ctx.parser.parse_args(['publish', '--help'])
55 return 54 return
56 ctx.args.sub_func(ctx) 55 ctx.args.sub_func(ctx)
57 56
58 def _doPublish(self, ctx): 57 def _doPublish(self, ctx):
58 from piecrust.publishing.publisher import Publisher
59
59 pub = Publisher(ctx.app) 60 pub = Publisher(ctx.app)
60 pub.run( 61 pub.run(
61 ctx.args.target, 62 ctx.args.target,
62 preview=ctx.args.preview, 63 preview=ctx.args.preview,
63 extra_args=ctx.args, 64 extra_args=ctx.args,
64 log_file=ctx.args.log_publisher, 65 log_file=ctx.args.log_publisher,
65 applied_config_variant=ctx.config_variant, 66 applied_config_variant=ctx.config_variant,
66 applied_config_values=ctx.config_values) 67 applied_config_values=ctx.config_values)
67 68