Mercurial > piecrust2
comparison piecrust/publishing/publisher.py @ 879:58ae026b4c31
chef: Optimize startup time.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Jun 2017 22:38:05 -0700 |
parents | 6abb436fea5b |
children |
comparison
equal
deleted
inserted
replaced
878:313db67cfc35 | 879:58ae026b4c31 |
---|---|
1 import os.path | 1 import os.path |
2 import time | 2 import time |
3 import logging | 3 import logging |
4 import urllib.parse | |
5 from piecrust.chefutil import format_timed | 4 from piecrust.chefutil import format_timed |
6 from piecrust.publishing.base import PublishingContext | 5 from piecrust.publishing.base import PublishingContext |
7 | 6 |
8 | 7 |
9 logger = logging.getLogger(__name__) | 8 logger = logging.getLogger(__name__) |
28 | 27 |
29 # Get publisher for this target. | 28 # Get publisher for this target. |
30 pub = self.app.getPublisher(target) | 29 pub = self.app.getPublisher(target) |
31 if pub is None: | 30 if pub is None: |
32 raise InvalidPublishTargetError( | 31 raise InvalidPublishTargetError( |
33 "No such publish target: %s" % target) | 32 "No such publish target: %s" % target) |
34 | 33 |
35 # Will we need to bake first? | 34 # Will we need to bake first? |
36 bake_first = True | 35 bake_first = True |
37 if not pub.has_url_config: | 36 if not pub.has_url_config: |
38 bake_first = pub.getConfigValue('bake', True) | 37 bake_first = pub.getConfigValue('bake', True) |
59 bake_start_time = time.perf_counter() | 58 bake_start_time = time.perf_counter() |
60 logger.debug("Baking first to: %s" % bake_out_dir) | 59 logger.debug("Baking first to: %s" % bake_out_dir) |
61 | 60 |
62 from piecrust.baking.baker import Baker | 61 from piecrust.baking.baker import Baker |
63 baker = Baker( | 62 baker = Baker( |
64 self.app, bake_out_dir, | 63 self.app, bake_out_dir, |
65 applied_config_variant=applied_config_variant, | 64 applied_config_variant=applied_config_variant, |
66 applied_config_values=applied_config_values) | 65 applied_config_values=applied_config_values) |
67 rec1 = baker.bake() | 66 rec1 = baker.bake() |
68 | 67 |
69 from piecrust.processing.pipeline import ProcessorPipeline | 68 from piecrust.processing.pipeline import ProcessorPipeline |
70 proc = ProcessorPipeline( | 69 proc = ProcessorPipeline( |
71 self.app, bake_out_dir, | 70 self.app, bake_out_dir, |
72 applied_config_variant=applied_config_variant, | 71 applied_config_variant=applied_config_variant, |
73 applied_config_values=applied_config_values) | 72 applied_config_values=applied_config_values) |
74 rec2 = proc.run() | 73 rec2 = proc.run() |
75 | 74 |
76 was_baked = True | 75 was_baked = True |
77 | 76 |
78 if not rec1.success or not rec2.success: | 77 if not rec1.success or not rec2.success: |
79 raise Exception( | 78 raise Exception( |
80 "Error during baking, aborting publishing.") | 79 "Error during baking, aborting publishing.") |
81 logger.info(format_timed(bake_start_time, "Baked website.")) | 80 logger.info(format_timed(bake_start_time, "Baked website.")) |
82 else: | 81 else: |
83 logger.info("Would bake to: %s" % bake_out_dir) | 82 logger.info("Would bake to: %s" % bake_out_dir) |
84 | 83 |
85 # Publish! | 84 # Publish! |
86 logger.debug( | 85 logger.debug( |
87 "Running publish target '%s' with publisher: %s" % | 86 "Running publish target '%s' with publisher: %s" % |
88 (target, pub.PUBLISHER_NAME)) | 87 (target, pub.PUBLISHER_NAME)) |
89 pub_start_time = time.perf_counter() | 88 pub_start_time = time.perf_counter() |
90 | 89 |
91 ctx = PublishingContext() | 90 ctx = PublishingContext() |
92 ctx.bake_out_dir = bake_out_dir | 91 ctx.bake_out_dir = bake_out_dir |
93 ctx.bake_record = rec1 | 92 ctx.bake_record = rec1 |
97 ctx.args = extra_args | 96 ctx.args = extra_args |
98 try: | 97 try: |
99 pub.run(ctx) | 98 pub.run(ctx) |
100 except Exception as ex: | 99 except Exception as ex: |
101 raise PublishingError( | 100 raise PublishingError( |
102 "Error publishing to target: %s" % target) from ex | 101 "Error publishing to target: %s" % target) from ex |
103 finally: | 102 finally: |
104 if hdlr: | 103 if hdlr: |
105 root_logger.removeHandler(hdlr) | 104 root_logger.removeHandler(hdlr) |
106 hdlr.close() | 105 hdlr.close() |
107 | 106 |