Skip to content
Snippets Groups Projects
Commit 734dcad4 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

use counter instead of time for name of tmp zip file in ssh_client upload/download files

parent 93095cf9
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -116,6 +116,8 @@ class SSHClient(object):
self.ssh_lock = threading.RLock()
#self.sftp = None
self.transport = None
self.counter_lock = threading.RLock()
self.counter=0
if key is not None:
self.key = paramiko.RSAKey.from_private_key(StringIO(key), password=passphrase)
......@@ -254,7 +256,9 @@ class SSHClient(object):
files = set([os.path.abspath(f) for f in files])
compression_levels = {0:zipfile.ZIP_STORED, 1:zipfile.ZIP_DEFLATED, 2:zipfile.ZIP_BZIP2, 3:zipfile.ZIP_LZMA}
zn = 'tmp_%s_%s.zip'%(id(self),time.time())
with self.counter_lock:
self.counter+=1
zn = 'tmp_%s_%04d.zip'%(id(self),self.counter)
zipf = zipfile.ZipFile(zn, 'w', compression_levels[compression_level])
try:
for f in files:
......@@ -276,7 +280,9 @@ class SSHClient(object):
if not isinstance(file_lst, (tuple, list)):
file_lst = [file_lst]
file_lst = [f.replace("\\","/") for f in file_lst]
zn = 'tmp_%s_%s.zip'%(id(self),time.time())
with self.counter_lock:
self.counter+=1
zn = 'tmp_%s_%04d.zip'%(id(self),self.counter)
remote_zip = os.path.join(remote_path, zn).replace("\\","/")
self.execute("cd %s && zip -r %s %s"%(remote_path, zn, " ".join(file_lst)))
......
......@@ -34,7 +34,7 @@ class sshrisoe_interactive_auth_handler(object):
return []
tfp = os.path.join(os.path.dirname(__file__), 'test_files/')
all = 0
all = 1
class TestSSHClient(unittest.TestCase):
def setUp(self):
......@@ -87,7 +87,7 @@ class TestSSHClient(unittest.TestCase):
def test_folder_transfer_specific_files_uppercase(self):
if 0 or all:
if 1 or all:
if x:
p = tfp
files = [os.path.join(tfp, "TEST.txt")]
......@@ -99,7 +99,7 @@ class TestSSHClient(unittest.TestCase):
def test_folder_transfer_specific_files(self):
if 0 or all:
if 1 or all:
if x:
p = r"C:\mmpe\HAWC2\models\version_12.3beta/"
p = r'C:\mmpe\programming\python\WindEnergyToolbox\wetb\hawc2\tests\test_files\simulation_setup\DTU10MWRef6.0_IOS/'
......@@ -132,7 +132,7 @@ class TestSSHClient(unittest.TestCase):
self.assertEqual(out.strip(), "ssh-03.risoe.dk")
def test_ssh_risoe_gorm(self):
if 1 or all:
if 0 or all:
if x:
gateway = SSHClient('ssh.risoe.dk', 'mmpe', password="xxx", interactive_auth_handler = sshrisoe_interactive_auth_handler(x.mmpe))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment