mirror of
https://github.com/HuFlungDu/pylibmeshctrl.git
synced 2026-02-20 13:42:11 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20843dbea7 | ||
|
|
af6c020506 |
@@ -31,6 +31,7 @@ class Session(object):
|
||||
proxy (str): "url:port" to use for proxy server NOTE: This is currently not implemented due to a limitation of the undersying websocket library. Upvote the issue if you find this important.
|
||||
token (str): Login token. This appears to be superfluous
|
||||
ignore_ssl (bool): Ignore SSL errors
|
||||
auto_reconnect (bool): In case of server failure, attempt to auto reconnect. All outstanding requests will be killed.
|
||||
|
||||
Returns:
|
||||
:py:class:`Session`: Session connected to url
|
||||
@@ -92,6 +93,7 @@ class Session(object):
|
||||
self._inflight = set()
|
||||
self._file_tunnels = {}
|
||||
self._ignore_ssl = ignore_ssl
|
||||
self.auto_reconnect = auto_reconnect
|
||||
|
||||
self._eventer = util.Eventer()
|
||||
|
||||
@@ -1859,17 +1861,20 @@ class Session(object):
|
||||
:py:class:`~meshctrl.exceptions.FileTransferCancelled`: File transfer cancelled. Info available on the `stats` property
|
||||
|
||||
Returns:
|
||||
io.IOBase: The stream which has been downloaded into. Cursor will be at the end of the stream.
|
||||
io.IOBase: The stream which has been downloaded into. Cursor will be at the beginning of where the file is downloaded.
|
||||
'''
|
||||
if target is None:
|
||||
target = io.BytesIO()
|
||||
start = target.tell()
|
||||
if unique_file_tunnel:
|
||||
async with self.file_explorer(nodeid) as files:
|
||||
await files.download(source, target)
|
||||
target.seek(start)
|
||||
return target
|
||||
else:
|
||||
files = await self._cached_file_explorer(nodeid, nodeid)
|
||||
await files.download(source, target, timeout=timeout)
|
||||
target.seek(start)
|
||||
return target
|
||||
|
||||
async def download_file(self, nodeid, source, filepath, unique_file_tunnel=False, timeout=None):
|
||||
@@ -1887,10 +1892,10 @@ class Session(object):
|
||||
:py:class:`~meshctrl.exceptions.FileTransferCancelled`: File transfer cancelled. Info available on the `stats` property
|
||||
|
||||
Returns:
|
||||
io.IOBase: The stream which has been downloaded into. Cursor will be at the end of the stream.
|
||||
None
|
||||
'''
|
||||
with open(filepath, "wb") as f:
|
||||
return await self.download(nodeid, source, f, unique_file_tunnel, timeout=timeout)
|
||||
await self.download(nodeid, source, f, unique_file_tunnel, timeout=timeout)
|
||||
|
||||
async def _cached_file_explorer(self, nodeid, _id):
|
||||
if (_id not in self._file_tunnels or not self._file_tunnels[_id].alive):
|
||||
|
||||
@@ -396,11 +396,9 @@ async def test_session_files(env):
|
||||
assert r["size"] == len(randdata), "Uploaded wrong number of bytes"
|
||||
|
||||
s = await admin_session.download(agent.nodeid, f"{pwd}/test", timeout=5)
|
||||
s.seek(0)
|
||||
assert s.read() == randdata, "Downloaded bad data"
|
||||
|
||||
await admin_session.download(agent.nodeid, f"{pwd}/test", downfilestream, timeout=5)
|
||||
downfilestream.seek(0)
|
||||
assert downfilestream.read() == randdata, "Downloaded bad data"
|
||||
|
||||
await admin_session.download_file(agent.nodeid, f"{pwd}/test2", os.path.join(thisdir, "data", "test"), timeout=5)
|
||||
|
||||
Reference in New Issue
Block a user