Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pycomsdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
com
pycomsdk
Commits
38c24765
Commit
38c24765
authored
Apr 08, 2020
by
Anton Pershin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил опциональный вывод сообщений на экран в методах BaseCommunication и наследниках
parent
295cb6e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
communication.py
comsdk/communication.py
+17
-13
No files found.
comsdk/communication.py
View file @
38c24765
...
...
@@ -94,7 +94,7 @@ class BaseCommunication(metaclass=ABCMeta):
pass
@abstractmethod
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
):
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
,
show_msg
=
False
):
'''
Copies from_ to to_ which are interpreted according to mode:
(1) from_local (default) -> from_ is local path, to_ is a path on a communicated machine
...
...
@@ -148,11 +148,12 @@ class LocalCommunication(BaseCommunication):
subprocess
.
call
([
command_line
],
shell
=
True
)
return
[],
[]
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
):
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
,
show_msg
=
False
):
'''
Any mode is ignored since the copying shall be within a local machine anyway
'''
#self._print_copy_msg(from_, to_)
if
show_msg
:
self
.
_print_copy_msg
(
from_
,
to_
)
return
cp
(
from_
,
to_
)
def
rm
(
self
,
target
):
...
...
@@ -216,18 +217,19 @@ class SshCommunication(BaseCommunication):
# for line in stderr:
# print('\t\t' + line.strip('\n'))
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
):
def
copy
(
self
,
from_
,
to_
,
mode
=
'from_local'
,
show_msg
=
False
):
if
self
.
ssh_client
is
None
:
raise
Exception
(
'Remote host is not set'
)
self
.
_init_sftp
()
new_path
=
None
if
mode
==
'from_local'
:
new_path
=
self
.
_copy_from_local
(
from_
,
to_
)
new_path
=
self
.
_copy_from_local
(
from_
,
to_
,
show_msg
)
elif
mode
==
'from_remote'
:
new_path
=
self
.
_copy_from_remote
(
from_
,
to_
)
new_path
=
self
.
_copy_from_remote
(
from_
,
to_
,
show_msg
)
elif
mode
==
'all_remote'
:
# self._print_copy_msg(self._machine_name + ':' + from_, self._machine_name + ':' + to_)
if
show_msg
:
self
.
_print_copy_msg
(
self
.
machine_name
+
':'
+
from_
,
self
.
machine_name
+
':'
+
to_
)
self
.
_mkdirp
(
to_
)
self
.
execute
(
'cp -r
%
s
%
s'
%
(
from_
,
to_
))
else
:
...
...
@@ -287,29 +289,31 @@ class SshCommunication(BaseCommunication):
except
IOError
:
return
False
def
_copy_from_local
(
self
,
from_
,
to_
):
def
_copy_from_local
(
self
,
from_
,
to_
,
show_msg
=
False
):
new_path_on_remote
=
to_
+
'/'
+
os
.
path
.
basename
(
from_
)
if
os
.
path
.
isfile
(
from_
):
self
.
_mkdirp
(
to_
)
# self._print_copy_msg(from_, self._machine_name + ':' + to_)
if
show_msg
:
self
.
_print_copy_msg
(
from_
,
self
.
machine_name
+
':'
+
to_
)
self
.
_put
(
from_
,
new_path_on_remote
)
elif
os
.
path
.
isdir
(
from_
):
self
.
mkdir
(
new_path_on_remote
)
for
dir_or_file
in
os
.
listdir
(
from_
):
self
.
_copy_from_local
(
os
.
path
.
join
(
from_
,
dir_or_file
),
new_path_on_remote
)
self
.
_copy_from_local
(
os
.
path
.
join
(
from_
,
dir_or_file
),
new_path_on_remote
,
show_msg
)
else
:
raise
CommunicationError
(
"Path
%
s does not exist"
%
from_
)
return
new_path_on_remote
def
_copy_from_remote
(
self
,
from_
,
to_
):
def
_copy_from_remote
(
self
,
from_
,
to_
,
show_msg
=
False
):
new_path_on_local
=
os
.
path
.
join
(
to_
,
os
.
path
.
basename
(
from_
))
if
not
self
.
_is_remote_dir
(
from_
):
# self._print_copy_msg(self._machine_name + ':' + from_, to_)
if
show_msg
:
self
.
_print_copy_msg
(
self
.
machine_name
+
':'
+
from_
,
to_
)
self
.
_get
(
from_
,
new_path_on_local
)
else
:
os
.
mkdir
(
new_path_on_local
)
for
dir_or_file
in
self
.
sftp_client
.
listdir
(
from_
):
self
.
_copy_from_remote
(
from_
+
'/'
+
dir_or_file
,
new_path_on_local
)
self
.
_copy_from_remote
(
from_
+
'/'
+
dir_or_file
,
new_path_on_local
,
show_msg
)
return
new_path_on_local
def
disconnect
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment