annotate piecrust/publishing/sftp.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 3b33d9fb007c
children 5713b6a2850d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import urllib.parse
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import getpass
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import logging
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 import paramiko
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 from piecrust.publishing.base import Publisher, PublisherConfigurationError
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 logger = logging.getLogger(__name__)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 class SftpPublisher(Publisher):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 PUBLISHER_NAME = 'sftp'
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 PUBLISHER_SCHEME = 'sftp'
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 def setupPublishParser(self, parser, app):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 parser.add_argument(
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
19 '--force',
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
20 action='store_true',
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
21 help=("Upload the entire bake directory instead of only "
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
22 "the files changed by the last bake."))
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
23
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
24 def parseUrlTarget(self, url):
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
25 self.config = {'host': str(url)}
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 def run(self, ctx):
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
28 host = self.config.get('host')
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
29 if not host:
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
30 raise PublisherConfigurationError(
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
31 "Publish target '%s' doesn't specify a 'host'." %
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
32 self.target)
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
33 remote = urllib.parse.urlparse(host)
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 hostname = remote.hostname
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 port = remote.port or 22
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 path = remote.path
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 if not hostname:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 hostname = path
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 path = ''
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
42 username = self.config.get('username', remote.username)
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
43 path = self.config.get('path', path)
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
44 pkey_path = self.config.get('key')
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 password = None
767
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
47 if username and not ctx.preview:
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 password = getpass.getpass("Password for '%s': " % username)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
767
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
50 if ctx.preview:
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
51 logger.info("Would connect to %s:%s..." % (hostname, port))
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
52 self._previewUpload(ctx, path)
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
53 return
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
54
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 logger.debug("Connecting to %s:%s..." % (hostname, port))
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 lfk = (not username and not pkey_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 sshc = paramiko.SSHClient()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 sshc.load_system_host_keys()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 sshc.set_missing_host_key_policy(paramiko.WarningPolicy())
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 sshc.connect(
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
61 hostname, port=port,
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
62 username=username, password=password,
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
63 key_filename=pkey_path,
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
64 look_for_keys=lfk)
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 try:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 logger.info("Connected as %s" %
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 sshc.get_transport().get_username())
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 client = sshc.open_sftp()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 try:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 self._upload(sshc, client, ctx, path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 finally:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 client.close()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 finally:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 sshc.close()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
767
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
76 def _previewUpload(self, ctx, dest_dir):
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
77 if not ctx.args.force:
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
78 logger.info("Would upload new/changed files...")
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
79 else:
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
80 logger.info("Would upload entire website...")
3b33d9fb007c publish: Add support for `--preview` for the SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 759
diff changeset
81
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 def _upload(self, session, client, ctx, dest_dir):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 if dest_dir:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 if dest_dir.startswith('~/'):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 _, out_chan, _ = session.exec_command("echo $HOME")
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 home_dir = out_chan.read().decode('utf8').strip()
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 dest_dir = home_dir + dest_dir[1:]
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 logger.debug("CHDIR %s" % dest_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 try:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 client.chdir(dest_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 except IOError:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 client.mkdir(dest_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 client.chdir(dest_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 known_dirs = {}
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 if ctx.was_baked and not ctx.args.force:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 to_upload = list(self.getBakedFiles(ctx))
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 to_delete = list(self.getDeletedFiles(ctx))
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 if to_upload or to_delete:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 logger.info("Uploading new/changed files...")
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 for path in self.getBakedFiles(ctx):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 rel_path = os.path.relpath(path, ctx.bake_out_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 logger.info(rel_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 if not ctx.preview:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 self._putFile(client, path, rel_path, known_dirs)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 logger.info("Deleting removed files...")
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 for path in self.getDeletedFiles(ctx):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 rel_path = os.path.relpath(path, ctx.bake_out_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 logger.info("%s [DELETE]" % rel_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 if not ctx.preview:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 try:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 client.remove(rel_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 except OSError:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 pass
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 else:
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
116 logger.info(
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
117 "Nothing to upload or delete on the remote server.")
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
118 logger.info(
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
119 "If you want to force uploading the entire website, "
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
120 "use the `--force` flag.")
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 else:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 logger.info("Uploading entire website...")
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 for dirpath, dirnames, filenames in os.walk(ctx.bake_out_dir):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 for f in filenames:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 abs_f = os.path.join(dirpath, f)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 rel_f = os.path.relpath(abs_f, ctx.bake_out_dir)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 logger.info(rel_f)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 if not ctx.preview:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 self._putFile(client, abs_f, rel_f, known_dirs)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 def _putFile(self, client, local_path, remote_path, known_dirs):
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 # Split the remote path in bits.
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 remote_path = os.path.normpath(remote_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 if os.sep != '/':
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 remote_path = remote_path.sub(os.sep, '/')
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 # Make sure each directory in the remote path exists... to prevent
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 # testing the same directories several times, we keep a cache of
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 # `known_dirs` which we know exist.
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 remote_bits = remote_path.split('/')
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 cur = ''
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142 for b in remote_bits[:-1]:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 cur = os.path.join(cur, b)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 if cur not in known_dirs:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 try:
885
13e8b50a2113 publish: Fix publishers API and add a simple "copy" publisher.
Ludovic Chabant <ludovic@chabant.com>
parents: 767
diff changeset
146 client.stat(cur)
759
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 except FileNotFoundError:
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 logger.debug("Creating remote dir: %s" % cur)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 client.mkdir(cur)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 known_dirs[cur] = True
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 # Should be all good! Upload the file.
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 client.put(local_path, remote_path)
dd03385adb62 publish: Add SFTP publisher.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154