comparison piecrust/publishing/sftp.py @ 767:3b33d9fb007c

publish: Add support for `--preview` for the SFTP publisher.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 02 Jul 2016 01:27:56 -0700
parents dd03385adb62
children 13e8b50a2113
comparison
equal deleted inserted replaced
766:f69fdc601845 767:3b33d9fb007c
49 path = self.getConfigValue('path') 49 path = self.getConfigValue('path')
50 50
51 pkey_path = self.getConfigValue('key') 51 pkey_path = self.getConfigValue('key')
52 52
53 password = None 53 password = None
54 if username: 54 if username and not ctx.preview:
55 password = getpass.getpass("Password for '%s': " % username) 55 password = getpass.getpass("Password for '%s': " % username)
56
57 if ctx.preview:
58 logger.info("Would connect to %s:%s..." % (hostname, port))
59 self._previewUpload(ctx, path)
60 return
56 61
57 logger.debug("Connecting to %s:%s..." % (hostname, port)) 62 logger.debug("Connecting to %s:%s..." % (hostname, port))
58 lfk = (not username and not pkey_path) 63 lfk = (not username and not pkey_path)
59 sshc = paramiko.SSHClient() 64 sshc = paramiko.SSHClient()
60 sshc.load_system_host_keys() 65 sshc.load_system_host_keys()
72 self._upload(sshc, client, ctx, path) 77 self._upload(sshc, client, ctx, path)
73 finally: 78 finally:
74 client.close() 79 client.close()
75 finally: 80 finally:
76 sshc.close() 81 sshc.close()
82
83 def _previewUpload(self, ctx, dest_dir):
84 if not ctx.args.force:
85 logger.info("Would upload new/changed files...")
86 else:
87 logger.info("Would upload entire website...")
77 88
78 def _upload(self, session, client, ctx, dest_dir): 89 def _upload(self, session, client, ctx, dest_dir):
79 if dest_dir: 90 if dest_dir:
80 if dest_dir.startswith('~/'): 91 if dest_dir.startswith('~/'):
81 _, out_chan, _ = session.exec_command("echo $HOME") 92 _, out_chan, _ = session.exec_command("echo $HOME")