-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutility.py
60 lines (50 loc) · 1.25 KB
/
utility.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
import os
import re
import sys
from config import TMP_DIR
def b64_url_to_std(val: str) -> str:
replacements = [
(r"\u002d", "+"),
(r"\x5f", "/"),
]
for pattern, repl in replacements:
val = re.sub(pattern, repl, val, 0)
return val
def b64_std_to_url(val: str) -> str:
replacements = [
(r"\+", "-"),
(r"\/", "_"),
(r"=+$", ""),
]
for pattern, repl in replacements:
val = re.sub(pattern, repl, val, 0)
return val
# This is good enough
def safe_name(val: str) -> str:
replacements = [
(r"<", ""),
(r">", ""),
(r":", ""),
(r"\/", ""),
(r"\\", ""),
(r"\|", ""),
(r"\?", ""),
(r"\*", ""),
(r"\"", ""),
(r",", ""),
]
for pattern, repl in replacements:
val = re.sub(pattern, repl, val, 0)
return val
def print_with_asterisk(*vals: list[str]) -> None:
print("*" * os.get_terminal_size().columns)
for val in vals:
print(val)
def delete_temp_files() -> None:
if TMP_DIR != "./tmp":
print("Temp file is not the default")
sys.exit()
if not os.path.exists(TMP_DIR):
return
for file in os.listdir(TMP_DIR):
os.remove(f"{TMP_DIR}/{file}")