-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
71 lines (63 loc) · 1.97 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
def handler(signum, frame, print_func):
print_func()
sys.exit(0)
def split_into_parts(lst, parts):
length = len(lst)
div_size = length // parts
remainder = length % parts
start = 0
for _ in range(parts):
end = start + div_size + (1 if remainder > 0 else 0)
yield lst[start:end]
start = end
remainder -= 1
def print_results(results):
results = sorted(results, key=lambda d: d["latency"])
print("\nRESULTS\n")
print("Servers with the lowest latency")
if len(results) < 5:
for j in range(len(results)):
print(
"Hostname: {hostname:15s}| latency: {latency:10s} protocol: {protocol:10s} provider: {provider:10s}".format(
hostname=results[j]["hostname"],
latency=str(results[j]["latency"]) + "ms",
protocol=results[j]["protocol"],
provider=results[j]["provider"],
)
)
else:
for j in range(5):
print(
"Hostname: {hostname:15s}| latency: {latency:10s} protocol: {protocol:10s} provider: {provider:10s}".format(
hostname=results[j]["hostname"],
latency=str(results[j]["latency"]) + "ms",
protocol=results[j]["protocol"],
provider=results[j]["provider"],
)
)
def check_skip(
country_code,
provider,
protocol,
stboot,
owned,
country,
owned_flag,
server_type,
exclude_provider,
exclude_protocol,
):
return (
(country and country_code not in country)
or (owned_flag and not owned)
or (
server_type
and (
(stboot and server_type == "disk")
or (not stboot and server_type == "ram")
)
)
or (exclude_provider and provider in exclude_provider)
or (protocol == exclude_protocol)
)