diff --git a/wetb/utils/cluster_tools/ssh_client.py b/wetb/utils/cluster_tools/ssh_client.py index 66886fe362554a1f47e1b2d387821f64e06c95cc..7492b1a8079d0cf1489454604db2be3078039b2f 100644 --- a/wetb/utils/cluster_tools/ssh_client.py +++ b/wetb/utils/cluster_tools/ssh_client.py @@ -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))) diff --git a/wetb/utils/tests/test_ssh_client.py b/wetb/utils/tests/test_ssh_client.py index 022caddbd287c5b4814b53455472ddcf7c5fc6ac..f1f294fec507e71a2bbfb7127824c18019054879 100644 --- a/wetb/utils/tests/test_ssh_client.py +++ b/wetb/utils/tests/test_ssh_client.py @@ -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))