-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
36 lines (28 loc) · 928 Bytes
/
util.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
import os
overwrite_all = False
def confirm_overwrite(path):
global overwrite_all
if os.path.exists(path) and not overwrite_all:
answer = input(f"File '{path}' already exists. Overwrite (y(es)/a(ll)/N(o))? ").lower()
if answer.startswith("y"):
return True
elif answer.startswith("a"):
overwrite_all = True
return True
else:
raise FileExistsError(f"File '{path}' already exists.")
return True
def open_if_exists(file, mode='r'):
if file:
return open(file, mode=mode)
else:
class DummyOpener:
def __enter__(self):
return None
def __exit__(self, exc_type, exc_val, exc_tb):
pass
def ms_to_mm_ss_ms(ms):
minutes = ms // 60000
seconds = (ms // 1000) % 60
millis = ms % 1000
return "{:02d}:{:02d}.{:03d}".format(minutes, seconds, millis)