-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.py
97 lines (69 loc) · 2.17 KB
/
support.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import subprocess
import shutil
def run_command(command_list: list, print_output: bool = True) -> None:
if print_output:
print("Command:" + " ".join(command_list))
result = subprocess.run(command_list, capture_output=True, text=True)
if print_output:
print(result.stdout)
print(result.stderr)
def run_py_script(command_list: list, print_output: bool = True) -> None:
if print_output:
print("Command:" + " ".join(command_list))
result = subprocess.run(command_list, stdout=subprocess.PIPE, shell=True)
if print_output:
print(result.stdout)
print(result.stderr)
def copy_file(source_path, target_path):
try:
shutil.copy(source_path, target_path)
print(f"File copied from {source_path} to {target_path}")
except Exception as e:
print(f"Error: {e}")
def delete_file(filename: str) -> bool:
if not file_exists(filename):
return False
try:
os.remove(filename)
return True
except:
return False
def folder_exists(path: str) -> bool:
folder, file = os.path.split(path)
return os.path.isdir(folder)
def make_dir(path: str) -> None:
folder, file = os.path.split(path)
if not folder_exists(folder):
os.makedirs(folder)
def file_exists(file_path: str) -> bool:
return os.path.exists(file_path)
def get_script_dir() -> str:
return os.path.dirname(os.path.abspath(__file__))
def decima_lang_to_simplemma(decima_lang: str) -> str:
"""Only covers european languages to match lemmatizer"""
lookup = {
"English": "en",
"French": "fr",
"Spanish": "es",
"German": "de",
"Italian": "it",
"Dutch": "nl",
"Portuguese": "pt",
"TraditionalChinese": "",
"Korean": "",
"Russian": "ru",
"Polish": "pl",
"Danish": "da",
"Finnish": "fi",
"Norwegian": "nb",
"Swedish": "sv",
"Japanese": "",
"LatinAmericanSpanish": "es",
"BrazilianPortuguese": "pt",
"Turkish": "",
"Arabic": "tr",
"SimplifiedChinese": "",
}
output = lookup[decima_lang]
return output