comparison piecrust/publishing/sftp.py @ 923:5713b6a2850d

chef: Optimize startup time a little bit.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 29 Sep 2017 19:59:19 -0700
parents 13e8b50a2113
children
comparison
equal deleted inserted replaced
922:b447c24bc8d4 923:5713b6a2850d
1 import os 1 import os
2 import os.path 2 import os.path
3 import urllib.parse
4 import getpass
5 import logging 3 import logging
6 import paramiko
7 from piecrust.publishing.base import Publisher, PublisherConfigurationError 4 from piecrust.publishing.base import Publisher, PublisherConfigurationError
8 5
9 6
10 logger = logging.getLogger(__name__) 7 logger = logging.getLogger(__name__)
11 8
28 host = self.config.get('host') 25 host = self.config.get('host')
29 if not host: 26 if not host:
30 raise PublisherConfigurationError( 27 raise PublisherConfigurationError(
31 "Publish target '%s' doesn't specify a 'host'." % 28 "Publish target '%s' doesn't specify a 'host'." %
32 self.target) 29 self.target)
30
31 import urllib.parse
33 remote = urllib.parse.urlparse(host) 32 remote = urllib.parse.urlparse(host)
34 33
35 hostname = remote.hostname 34 hostname = remote.hostname
36 port = remote.port or 22 35 port = remote.port or 22
37 path = remote.path 36 path = remote.path
43 path = self.config.get('path', path) 42 path = self.config.get('path', path)
44 pkey_path = self.config.get('key') 43 pkey_path = self.config.get('key')
45 44
46 password = None 45 password = None
47 if username and not ctx.preview: 46 if username and not ctx.preview:
47 import getpass
48 password = getpass.getpass("Password for '%s': " % username) 48 password = getpass.getpass("Password for '%s': " % username)
49 49
50 if ctx.preview: 50 if ctx.preview:
51 logger.info("Would connect to %s:%s..." % (hostname, port)) 51 logger.info("Would connect to %s:%s..." % (hostname, port))
52 self._previewUpload(ctx, path) 52 self._previewUpload(ctx, path)
53 return 53 return
54
55 import paramiko
54 56
55 logger.debug("Connecting to %s:%s..." % (hostname, port)) 57 logger.debug("Connecting to %s:%s..." % (hostname, port))
56 lfk = (not username and not pkey_path) 58 lfk = (not username and not pkey_path)
57 sshc = paramiko.SSHClient() 59 sshc = paramiko.SSHClient()
58 sshc.load_system_host_keys() 60 sshc.load_system_host_keys()