Spaces:
Sleeping
Sleeping
Upload os_helper.py
Browse files- src/modules/os_helper.py +54 -0
src/modules/os_helper.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""OS helper functions."""
|
2 |
+
|
3 |
+
import os
|
4 |
+
import shutil
|
5 |
+
|
6 |
+
from modules.console_colors import ULTRASINGER_HEAD
|
7 |
+
|
8 |
+
|
9 |
+
def create_folder(folder_name: str) -> None:
|
10 |
+
"""Creates a folder if it doesn't exist."""
|
11 |
+
print(f"{ULTRASINGER_HEAD} Creating output folder. -> {folder_name}")
|
12 |
+
is_exist = os.path.exists(folder_name)
|
13 |
+
if not is_exist:
|
14 |
+
os.makedirs(folder_name)
|
15 |
+
|
16 |
+
|
17 |
+
def move(original: str, target: str) -> None:
|
18 |
+
"""Moves a file from one location to another."""
|
19 |
+
shutil.move(original, target)
|
20 |
+
|
21 |
+
|
22 |
+
def copy(original: str, target: str) -> None:
|
23 |
+
"""Copies a file from one location to another."""
|
24 |
+
shutil.copy(original, target)
|
25 |
+
|
26 |
+
|
27 |
+
def rename(original: str, target: str) -> None:
|
28 |
+
"""Renames a file."""
|
29 |
+
os.rename(original, target)
|
30 |
+
|
31 |
+
|
32 |
+
def current_executor_path() -> str:
|
33 |
+
"""Current executor path"""
|
34 |
+
return os.getcwd()
|
35 |
+
|
36 |
+
|
37 |
+
def path_join(path1: str, path2: str) -> str:
|
38 |
+
"""Joins two paths together"""
|
39 |
+
return os.path.join(path1, path2)
|
40 |
+
|
41 |
+
|
42 |
+
def check_file_exists(file_path: str) -> bool:
|
43 |
+
"""Checks if a file exists."""
|
44 |
+
return os.path.isfile(file_path)
|
45 |
+
|
46 |
+
|
47 |
+
def check_if_folder_exists(song_output: str) -> bool:
|
48 |
+
"""Checks if a folder exists."""
|
49 |
+
return os.path.isdir(song_output)
|
50 |
+
|
51 |
+
|
52 |
+
def remove_folder(cache_path):
|
53 |
+
"""Removes a folder."""
|
54 |
+
shutil.rmtree(cache_path)
|