Mercurial > piecrust2
annotate piecrust/publishing/rsync.py @ 1188:a7c43131d871
bake: Fix file write flushing problem with Python 3.8+
Writing the cache files fails in Python 3.8 because it looks like flushing
behaviour has changed. We need to explicitly flush. And even then, in very
rare occurrences, it looks like it can still run into racing conditions,
so we do a very hacky and ugly "retry" loop when fetching cached data :(
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 15 Jun 2021 22:36:23 -0700 |
parents | 13e8b50a2113 |
children |
rev | line source |
---|---|
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
1 from piecrust.publishing.shell import ShellCommandPublisherBase |
622
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 class RsyncPublisher(ShellCommandPublisherBase): |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 PUBLISHER_NAME = 'rsync' |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 PUBLISHER_SCHEME = 'rsync' |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
8 def parseUrlTarget(self, url): |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
9 self.config = { |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
10 'destination': (url.netloc + url.path) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
11 } |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
12 |
622
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 def _getCommandArgs(self, ctx): |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
14 orig = self.config.get('source', ctx.bake_out_dir) |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
15 dest = self.config.get('destination') |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
16 if not dest: |
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
17 raise Exception("No destination specified.") |
622
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 |
885
13e8b50a2113
publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
763
diff
changeset
|
19 rsync_options = self.config.get('options') |
622
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 if rsync_options is None: |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 rsync_options = ['-avc', '--delete'] |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 args = ['rsync'] + rsync_options |
624
b45fb2137a07
publish: Add option to change the source for the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
622
diff
changeset
|
24 args += [orig, dest] |
622
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 return args |
5d8e0c8cdb5f
publish: Add the `rsync` publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 |