Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shfe1
WindEnergyToolbox
Commits
734dcad4
Commit
734dcad4
authored
7 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
use counter instead of time for name of tmp zip file in ssh_client upload/download files
parent
93095cf9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/utils/cluster_tools/ssh_client.py
+8
-2
8 additions, 2 deletions
wetb/utils/cluster_tools/ssh_client.py
wetb/utils/tests/test_ssh_client.py
+4
-4
4 additions, 4 deletions
wetb/utils/tests/test_ssh_client.py
with
12 additions
and
6 deletions
wetb/utils/cluster_tools/ssh_client.py
+
8
−
2
View file @
734dcad4
...
...
@@ -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
)))
...
...
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_ssh_client.py
+
4
−
4
View file @
734dcad4
...
...
@@ -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
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment