Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added callback to get and put #2217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions fabric/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,7 @@ def __init__(
self.forward_agent = forward_agent

if connect_timeout is None:
connect_timeout = self.ssh_config.get(
"connecttimeout", self.config.timeouts.connect
)
connect_timeout = self.ssh_config.get("connecttimeout", self.config.timeouts.connect)
if connect_timeout is not None:
connect_timeout = int(connect_timeout)
#: Connection timeout
Expand Down Expand Up @@ -856,7 +854,7 @@ def get(self, *args, **kwargs):

.. versionadded:: 2.0
"""
return Transfer(self).get(*args, **kwargs)
return Transfer(self).get(**kwargs)

def put(self, *args, **kwargs):
"""
Expand Down
12 changes: 6 additions & 6 deletions fabric/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def is_remote_dir(self, path):
except IOError:
return False

def get(self, remote, local=None, preserve_mode=True):
def get(self, remote, local=None, preserve_mode=True, callback=None):
"""
Copy a file from wrapped connection's host to the local filesystem.

Expand Down Expand Up @@ -168,9 +168,9 @@ def get(self, remote, local=None, preserve_mode=True):
#
# If local appears to be a file-like object, use sftp.getfo, not get
if is_file_like:
self.sftp.getfo(remotepath=remote, fl=local)
self.sftp.getfo(remotepath=remote, fl=local, callback=callback)
else:
self.sftp.get(remotepath=remote, localpath=local)
self.sftp.get(remotepath=remote, localpath=local, callback=callback)
# Set mode to same as remote end
# TODO: Push this down into SFTPClient sometime (requires backwards
# incompat release.)
Expand All @@ -187,7 +187,7 @@ def get(self, remote, local=None, preserve_mode=True):
connection=self.connection,
)

def put(self, local, remote=None, preserve_mode=True):
def put(self, local, remote=None, preserve_mode=True, callback=None):
"""
Upload a file from the local filesystem to the current connection.

Expand Down Expand Up @@ -303,12 +303,12 @@ def put(self, local, remote=None, preserve_mode=True):
pointer = local.tell()
try:
local.seek(0)
self.sftp.putfo(fl=local, remotepath=remote)
self.sftp.putfo(fl=local, remotepath=remote, callback=callback)
finally:
local.seek(pointer)
else:
debug("Uploading {!r} to {!r}".format(local, remote))
self.sftp.put(localpath=local, remotepath=remote)
self.sftp.put(localpath=local, remotepath=remote, callback=callback)
# Set mode to same as local end
# TODO: Push this down into SFTPClient sometime (requires backwards
# incompat release.)
Expand Down
1 change: 1 addition & 0 deletions fabric/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ def get_local_user():

username = win32api.GetUserName()
return username

2 changes: 1 addition & 1 deletion integration/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def manual_threading_works_okay(self):
for t in threads:
t.join(5) # Kinda slow, but hey, maybe the test runner is hot
while not queue.empty():
cxn, result, expected = queue.get(block=False)
cxn, result, expected = queue.get()
for resultword, expectedword in zip_longest(result, expected):
err = u"({2!r}, {3!r}->{4!r}) {0!r} != {1!r}".format(
resultword, expectedword, cxn, expected[0], expected[-1]
Expand Down
4 changes: 1 addition & 3 deletions tests/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def connection_params_as_dir(self, transfer):
assert result.local == "/local/host/somefile"

def remote_path_posixpath_bits(self, transfer):
result = transfer.get(
"parent/mid/leaf", "foo/{dirname}/bar/{basename}"
)
result = transfer.get("parent/mid/leaf", "foo/{dirname}/bar/{basename}")
# Recall that test harness sets remote apparent cwd as
# /remote/, thus dirname is /remote/parent/mid
assert result.local == "/local/foo/remote/parent/mid/bar/leaf"
Expand Down