-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmisc.py
More file actions
46 lines (32 loc) · 1.05 KB
/
misc.py
File metadata and controls
46 lines (32 loc) · 1.05 KB
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
import random
import string
import asyncio
def get_random_password(length=8):
characters = string.ascii_letters + string.digits
password = "".join(random.choice(characters) for x in range(length))
return password
async def wait_for_tcp(ip, port, retries=60):
for i in range(retries):
try:
_, writer = await asyncio.open_connection(ip, port)
writer.close()
await writer.wait_closed()
return True
except ConnectionRefusedError as e:
await asyncio.sleep(5)
else:
return False
def readable_time(elapsed):
readable = ""
days = int(elapsed / (60 * 60 * 24))
hours = int((elapsed / (60 * 60)) % 24)
minutes = int((elapsed % (60 * 60)) / 60)
if(days > 0):
readable += str(days) + " days "
if(hours > 0):
readable += str(hours) + " hours "
if(minutes > 0):
readable += str(minutes) + " minutes "
return readable
def contains_version_number(map_name: str) -> bool:
return bool(re.search(r"\d|final|rc"))