FIx mktemp dir and redundant Paramiko connecting.

Use previously initialized connection for sftp_get calls.
Use local directory for tarball temp file location.
This commit is contained in:
Warren Usui 2014-05-01 12:52:45 -07:00 committed by Zack Cerza
parent 36b07b8aee
commit 8bed6ab625
2 changed files with 2 additions and 10 deletions

View File

@ -625,7 +625,7 @@ def pull_directory(remote, remotedir, localdir):
remote.shortname, remotedir, localdir)
if not os.path.exists(localdir):
os.mkdir(localdir)
_, local_tarfile = tempfile.mkstemp()
_, local_tarfile = tempfile.mkstemp(dir=localdir)
remote.get_tar(remotedir, local_tarfile, sudo=True)
with open(local_tarfile, 'r+') as fb1:
tar = tarfile.open(mode='r|', fileobj=fb1)

View File

@ -73,10 +73,6 @@ class Remote(object):
def hostname(self):
return self.name.split('@')[1]
@property
def username(self):
return self.name.split('@')[0]
@property
def is_online(self):
if self.ssh is None:
@ -159,11 +155,7 @@ class Remote(object):
return result
def _sftp_copy_file(self, file_path, to_path):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(self.hostname, username=self.username)
sftp = client.open_sftp()
sftp = self.ssh.open_sftp()
sftp.get(file_path, to_path)
def remove(self, path):