From c1504d4d71afcd0764bfbb51578ebed556f36aec Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Tue, 21 Feb 2017 08:54:27 +0000 Subject: [PATCH] Added analysis options and analysis decorator --- trisurf/Remote.py | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 deletions(-) diff --git a/trisurf/Remote.py b/trisurf/Remote.py index 89a00bd..977b96a 100644 --- a/trisurf/Remote.py +++ b/trisurf/Remote.py @@ -1,5 +1,5 @@ import paramiko - +import os.path class Connection: def __init__(self, hostname, port=22, username=None, password=None): @@ -69,4 +69,33 @@ sftp.mkdir(directory) sftp.close() + def mkdir_p(self,sftp, remote_directory): + """Change to this directory, recursively making new folders if needed. + Returns True if any folders were created. Recursive algorithm.""" + if remote_directory == '/': + # absolute path so change directory to root + sftp.chdir('/') + return + if remote_directory == '': + # top-level relative directory must exist + return + try: + sftp.chdir(remote_directory) # sub-directory exists + except IOError: + dirname, basename = os.path.split(remote_directory.rstrip('/')) + self.mkdir_p(sftp, dirname) # make parent directories + sftp.mkdir(basename) # sub-directory missing, so created it + sftp.chdir(basename) + return True + def send_multiple_files_in_directory(self,local_files,directory): + sftp=self.ssh.open_sftp() +# try: +# sftp.chdir(directory) # Test if remote_path exists +# except (IOError,FileNotFoundError): +# sftp.mkdir(directory) # Create remote_path +# sftp.chdir(directory) + self.mkdir_p(sftp, directory) + for f in set(local_files): + sftp.put(f, f) + sftp.close() -- Gitblit v1.9.3