mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
connection: Cleanup TransferManager callback interface
Implement a sane interface avoiding variable positional arguments.
This commit is contained in:
parent
45aebdaca9
commit
e0b1176757
@ -717,12 +717,8 @@ class SSHTransferManager(TransferManagerBase):
|
|||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def progress_cb(self, *args):
|
def progress_cb(self, to_transfer, transferred):
|
||||||
if self.transfer_started.is_set():
|
if self.transfer_started.is_set():
|
||||||
self.progressed = True
|
self.progressed = True
|
||||||
if len(args) == 3: # For SCPClient callbacks
|
self.transferred = transferred
|
||||||
self.transferred = args[2]
|
self.to_transfer = to_transfer
|
||||||
self.to_transfer = args[1]
|
|
||||||
elif len(args) == 2: # For SFTPClient callbacks
|
|
||||||
self.transferred = args[0]
|
|
||||||
self.to_transfer = args[1]
|
|
||||||
|
@ -406,9 +406,6 @@ class SshConnection(SshConnectionBase):
|
|||||||
channel = transport.open_session()
|
channel = transport.open_session()
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def _get_progress_cb(self):
|
|
||||||
return self.transfer_mgr.progress_cb if self.transfer_mgr is not None else None
|
|
||||||
|
|
||||||
# Limit the number of opened channels to a low number, since some servers
|
# Limit the number of opened channels to a low number, since some servers
|
||||||
# will reject more connections request. For OpenSSH, this is controlled by
|
# will reject more connections request. For OpenSSH, this is controlled by
|
||||||
# the MaxSessions config.
|
# the MaxSessions config.
|
||||||
@ -430,10 +427,11 @@ class SshConnection(SshConnectionBase):
|
|||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache()
|
||||||
def _get_scp(self, timeout):
|
def _get_scp(self, timeout):
|
||||||
return SCPClient(self.client.get_transport(), socket_timeout=timeout, progress=self._get_progress_cb())
|
cb = lambda _, to_transfer, transferred: self.transfer_mgr.progress_cb(to_transfer, transferred)
|
||||||
|
return SCPClient(self.client.get_transport(), socket_timeout=timeout, progress=cb)
|
||||||
|
|
||||||
def _push_file(self, sftp, src, dst):
|
def _push_file(self, sftp, src, dst):
|
||||||
sftp.put(src, dst, callback=self._get_progress_cb())
|
sftp.put(src, dst, callback=self.transfer_mgr.progress_cb)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _path_exists(cls, sftp, path):
|
def _path_exists(cls, sftp, path):
|
||||||
@ -463,7 +461,7 @@ class SshConnection(SshConnectionBase):
|
|||||||
push(sftp, src, dst)
|
push(sftp, src, dst)
|
||||||
|
|
||||||
def _pull_file(self, sftp, src, dst):
|
def _pull_file(self, sftp, src, dst):
|
||||||
sftp.get(src, dst, callback=self._get_progress_cb())
|
sftp.get(src, dst, callback=self.transfer_mgr.progress_cb)
|
||||||
|
|
||||||
def _pull_folder(self, sftp, src, dst):
|
def _pull_folder(self, sftp, src, dst):
|
||||||
os.makedirs(dst)
|
os.makedirs(dst)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user