speedtest-ssh 1.2.0__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/PKG-INFO +1 -1
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh/__init__.py +1 -1
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh/speedtest_ssh.py +11 -11
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/PKG-INFO +1 -1
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/LICENSE +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/README.md +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/pyproject.toml +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/setup.cfg +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh/py.typed +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/SOURCES.txt +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/dependency_links.txt +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/entry_points.txt +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/requires.txt +0 -0
- {speedtest_ssh-1.2.0 → speedtest_ssh-1.3.0}/speedtest_ssh.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from tempfile import mkdtemp
|
|
3
3
|
from pathlib import Path
|
|
4
|
+
from math import log
|
|
4
5
|
import argparse
|
|
5
6
|
import shutil
|
|
6
7
|
import socket
|
|
@@ -15,7 +16,7 @@ import paramiko
|
|
|
15
16
|
from . import __version__
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
_base_size =
|
|
19
|
+
_base_size = 2 * (1024**2)
|
|
19
20
|
_ssh_timeout = 10
|
|
20
21
|
|
|
21
22
|
|
|
@@ -40,7 +41,7 @@ class ProgressBar(tqdm):
|
|
|
40
41
|
:param bytes_remaining: The number of bytes yet to be transferred
|
|
41
42
|
"""
|
|
42
43
|
if self.total is None:
|
|
43
|
-
self.total =
|
|
44
|
+
self.total = bytes_remaining
|
|
44
45
|
self.update(bytes_done - self.n)
|
|
45
46
|
|
|
46
47
|
|
|
@@ -62,7 +63,7 @@ def _ur_file(size: int, d: Path) -> Path:
|
|
|
62
63
|
return ret
|
|
63
64
|
|
|
64
65
|
|
|
65
|
-
def
|
|
66
|
+
def _get_stats(up_ns: int, down_ns: int, size: int) -> tuple[str, str]:
|
|
66
67
|
"""
|
|
67
68
|
:return: Up speed, down speed in Mbit/s
|
|
68
69
|
"""
|
|
@@ -93,13 +94,12 @@ def _iteration(local_d: Path, remote_d: str, ftp: paramiko.SFTPClient, size: int
|
|
|
93
94
|
return up, down
|
|
94
95
|
|
|
95
96
|
|
|
96
|
-
def speedtest_ssh(host: str,
|
|
97
|
+
def speedtest_ssh(host: str, num_seconds: int, **kwargs: str) -> None:
|
|
97
98
|
"""
|
|
98
99
|
speedtest_ssh, client shoule be False unless called by this program
|
|
99
100
|
"""
|
|
100
101
|
|
|
101
102
|
print("Initializing...")
|
|
102
|
-
max_seconds -= 1 # Assume overhead of 1 second or so
|
|
103
103
|
# Config
|
|
104
104
|
config = dict(kwargs)
|
|
105
105
|
config_f = Path.home() / ".ssh/config"
|
|
@@ -147,12 +147,12 @@ def speedtest_ssh(host: str, max_seconds: int, **kwargs: str) -> None:
|
|
|
147
147
|
nano_sec = 0
|
|
148
148
|
size = _base_size
|
|
149
149
|
try:
|
|
150
|
-
|
|
151
|
-
while nano_sec <
|
|
150
|
+
remaining: int = 1E9*num_seconds
|
|
151
|
+
while (1.5*nano_sec) < remaining:
|
|
152
|
+
size *= 2**(0 if not nano_sec else max(1, int(log(remaining / nano_sec, 2)))) # Faster than just *=2
|
|
152
153
|
up_t, down_t = _iteration(local_d, remote_d, ftp, size)
|
|
153
154
|
nano_sec = up_t + down_t
|
|
154
|
-
|
|
155
|
-
size /= 2
|
|
155
|
+
remaining -= nano_sec
|
|
156
156
|
ftp.close()
|
|
157
157
|
finally:
|
|
158
158
|
print("Cleaning up...")
|
|
@@ -164,7 +164,7 @@ def speedtest_ssh(host: str, max_seconds: int, **kwargs: str) -> None:
|
|
|
164
164
|
print(f"Failed to clean up, please run on remote host {host} the command: {cmd}")
|
|
165
165
|
raise
|
|
166
166
|
|
|
167
|
-
up, down =
|
|
167
|
+
up, down = _get_stats(up_t, down_t, size)
|
|
168
168
|
print("\n" + f"Upload Speed: {up}" + "\n" + f"Download Speed: {down}")
|
|
169
169
|
|
|
170
170
|
|
|
@@ -179,7 +179,7 @@ def main(argv: list[str]) -> None:
|
|
|
179
179
|
parser.add_argument("-u", "--username", default=None, help="The username to use to ssh")
|
|
180
180
|
parser.add_argument("--password", default=None, help="The password to use to ssh")
|
|
181
181
|
parser.add_argument("--port", type=int, default=None, help="The port to use to ssh")
|
|
182
|
-
parser.add_argument("--
|
|
182
|
+
parser.add_argument("--num_seconds", type=int, default=25, help="An approximate amount of time this test should take")
|
|
183
183
|
return speedtest_ssh(**vars(parser.parse_args(argv[1:])))
|
|
184
184
|
|
|
185
185
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|