-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
36 lines (26 loc) · 883 Bytes
/
utils.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
from datetime import datetime
import importlib
from termcolor import cprint
import aioconsole
def removeall(s: str, cs: str):
for c in cs:
s = s.replace(c, '')
return s
log_salt = removeall(str(datetime.now()), ' -:.')
LOG_FNAME = f'logs/debug_{log_salt}.txt'
print(f'Saving logs to {LOG_FNAME}')
def debug_log(msg):
cprint(msg, "dark_grey")
with open(LOG_FNAME, 'a+') as f:
f.write(str(msg) + '\n')
def warn_log(msg):
msg = 'WARN: ' + msg
cprint(msg, "yellow")
with open(LOG_FNAME, 'a+') as f:
f.write(str(msg) + '\n')
def threadsafe_start_pygame_loop(init_env, *events):
render = importlib.import_module('render') # necessary since render.py imports pygame which is not threadsafe
render.PygameView(init_env).loop(*events)
async def await_text_input():
text = await aioconsole.ainput("> ")
return text