speedtest-ssh 1.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: speedtest_ssh
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: A tool meant to check inter-device speeds over ssh
5
5
  License: GPL
6
6
  Project-URL: Homepage, https://github.com/zwimer/speedtest_ssh
@@ -1,3 +1,3 @@
1
- __version__ = "1.2.1"
1
+ __version__ = "1.3.0"
2
2
 
3
3
  from .speedtest_ssh import cli
@@ -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 = 4 * (1024**2)
19
+ _base_size = 2 * (1024**2)
19
20
  _ssh_timeout = 10
20
21
 
21
22
 
@@ -62,7 +63,7 @@ def _ur_file(size: int, d: Path) -> Path:
62
63
  return ret
63
64
 
64
65
 
65
- def get_stats(up_ns: int, down_ns: int, size: int) -> tuple[str, str]:
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, max_seconds: int, **kwargs: str) -> None:
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
- print("Testing speed...")
151
- while nano_sec < (max_seconds*1E9)//2:
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
- size *= 2
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 = get_stats(up_t, down_t, size)
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("--max_seconds", type=int, default=25, help="A very soft limit for how many seconds to spend uploading / downloading")
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: speedtest-ssh
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: A tool meant to check inter-device speeds over ssh
5
5
  License: GPL
6
6
  Project-URL: Homepage, https://github.com/zwimer/speedtest_ssh
File without changes
File without changes
File without changes