Mercurial > piecrust2
annotate piecrust/publishing/base.py @ 885:13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Jun 2017 21:12:35 -0700 |
parents | fd694f1297c7 |
children | d709429f02eb |
rev | line source |
---|---|
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
1 import os.path |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
2 import time |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
3 import logging |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
4 from piecrust.chefutil import format_timed |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
5 |
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
6 |
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
7 logger = logging.getLogger(__name__) |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
10 FILE_MODIFIED = 1 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
11 FILE_DELETED = 2 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
12 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
13 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
14 class PublisherConfigurationError(Exception): |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
15 pass |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
16 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
17 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
18 class PublishingContext: |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 def __init__(self): |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
20 self.bake_out_dir = None |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
21 self.bake_records = None |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
22 self.processing_record = None |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
23 self.was_baked = False |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
24 self.preview = False |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
25 self.args = None |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
28 class Publisher: |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
29 PUBLISHER_NAME = 'undefined' |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
30 PUBLISHER_SCHEME = None |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
31 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
32 def __init__(self, app, target, config): |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 self.app = app |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 self.target = 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 self.config = config |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 self.log_file_path = None |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
38 def setupPublishParser(self, parser, app): |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
39 return |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
40 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
41 def parseUrlTarget(self, url): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
42 raise NotImplementedError() |
613
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 def run(self, ctx): |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 raise NotImplementedError() |
e2e955a3bb25
publish: Add publish command.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
47 def getBakedFiles(self, ctx): |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
48 for rec in ctx.bake_records.records: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
49 for e in rec.getEntries(): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
50 paths = e.getAllOutputPaths() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
51 if paths is not None: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
52 yield from paths |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
53 |
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
54 def getDeletedFiles(self, ctx): |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
55 for rec in ctx.bake_records.records: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
56 yield from rec.deleted_out_paths |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
57 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
58 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
59 class InvalidPublishTargetError(Exception): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
60 pass |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
61 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
62 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
63 class PublishingError(Exception): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
64 pass |
758
6abb436fea5b
publish: Make publisher more powerful and better exposed on the command line.
Ludovic Chabant <ludovic@chabant.com>
parents:
621
diff
changeset
|
65 |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
66 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
67 class PublishingManager: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
68 def __init__(self, appfactory, app): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
69 self.appfactory = appfactory |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
70 self.app = app |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
71 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
72 def run(self, target, |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
73 force=False, preview=False, extra_args=None, log_file=None): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
74 start_time = time.perf_counter() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
75 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
76 # Get publisher for this target. |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
77 pub = self.app.getPublisher(target) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
78 if pub is None: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
79 raise InvalidPublishTargetError( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
80 "No such publish target: %s" % target) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
81 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
82 # Will we need to bake first? |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
83 bake_first = pub.config.get('bake', True) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
84 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
85 # Setup logging stuff. |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
86 hdlr = None |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
87 root_logger = logging.getLogger() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
88 if log_file and not preview: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
89 logger.debug("Adding file handler for: %s" % log_file) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
90 hdlr = logging.FileHandler(log_file, mode='w', encoding='utf8') |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
91 root_logger.addHandler(hdlr) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
92 if not preview: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
93 logger.info("Deploying to %s" % target) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
94 else: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
95 logger.info("Previewing deployment to %s" % target) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
96 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
97 # Bake first is necessary. |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
98 records = None |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
99 was_baked = False |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
100 bake_out_dir = os.path.join(self.app.root_dir, '_pub', target) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
101 if bake_first: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
102 if not preview: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
103 bake_start_time = time.perf_counter() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
104 logger.debug("Baking first to: %s" % bake_out_dir) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
105 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
106 from piecrust.baking.baker import Baker |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
107 baker = Baker( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
108 self.appfactory, self.app, bake_out_dir, force=force) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
109 records = baker.bake() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
110 was_baked = True |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
111 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
112 if not records.success: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
113 raise Exception( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
114 "Error during baking, aborting publishing.") |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
115 logger.info(format_timed(bake_start_time, "Baked website.")) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
116 else: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
117 logger.info("Would bake to: %s" % bake_out_dir) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
118 |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
119 # Publish! |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
120 logger.debug( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
121 "Running publish target '%s' with publisher: %s" % |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
122 (target, pub.PUBLISHER_NAME)) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
123 pub_start_time = time.perf_counter() |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
124 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
125 ctx = PublishingContext() |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
126 ctx.bake_out_dir = bake_out_dir |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
127 ctx.bake_records = records |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
128 ctx.was_baked = was_baked |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
129 ctx.preview = preview |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
130 ctx.args = extra_args |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
131 try: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
132 pub.run(ctx) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
133 except Exception as ex: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
134 raise PublishingError( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
135 "Error publishing to target: %s" % target) from ex |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
136 finally: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
137 if hdlr: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
138 root_logger.removeHandler(hdlr) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
139 hdlr.close() |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
140 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
141 logger.info(format_timed( |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
142 pub_start_time, "Ran publisher %s" % pub.PUBLISHER_NAME)) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
143 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
144 logger.info(format_timed(start_time, 'Deployed to %s' % target)) |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
145 |
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
146 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
147 def find_publisher_class(app, name, is_scheme=False): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
148 attr_name = 'PUBLISHER_SCHEME' if is_scheme else 'PUBLISHER_NAME' |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
149 for pub_cls in app.plugin_loader.getPublishers(): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
150 pub_sch = getattr(pub_cls, attr_name, None) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
151 if pub_sch == name: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
152 return pub_cls |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
153 return None |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
154 |
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
155 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
156 def find_publisher_name(app, scheme): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
157 pub_cls = find_publisher_class(app, scheme, True) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
158 if pub_cls: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
159 return pub_cls.PUBLISHER_NAME |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
805
diff
changeset
|
160 return None |
621
8f9c0bdb3724
publish: Polish/refactor the publishing workflows.
Ludovic Chabant <ludovic@chabant.com>
parents:
613
diff
changeset
|
161 |