forked from b-init/ImagePaste
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
101 lines (74 loc) · 2.76 KB
/
helper.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
98
99
100
101
import bpy
ADDON_NAME = __package__.split(".")[0]
def get_addon_preferences() -> bpy.types.AddonPreferences:
"""Get the addon preferences.
Returns:
bpy.types.AddonPreferences: The addon preferences.
"""
return bpy.context.preferences.addons[ADDON_NAME].preferences
def get_save_directory() -> str:
"""Get the path to the directory where the images are saved.
Returns:
str: The path to the directory where the images are saved.
"""
from os import makedirs
from os.path import exists
from os.path import dirname
from os.path import join
preferences = get_addon_preferences()
if not bpy.data.filepath:
if preferences.is_use_another_directory and preferences.another_directory:
return preferences.another_directory
return bpy.app.tempdir
if (
preferences.is_use_another_directory
and preferences.is_force_use_another_directory
and preferences.another_directory
):
return preferences.another_directory
directory_path = dirname(bpy.data.filepath)
if not preferences.is_use_subdirectory or not preferences.subdirectory_name:
return directory_path
subdirectory_path = join(directory_path, preferences.subdirectory_name)
if not exists(subdirectory_path):
makedirs(subdirectory_path)
return subdirectory_path
def is_valid_filename(filename: str) -> bool:
"""Check if the filename is valid.
Args:
filename (str): a string representing the file name.
Returns:
bool: True if the filename is valid, False otherwise.
"""
def is_windows_valid_filename(filename: str) -> bool:
"""Check if the filename is valid on Windows.
Args:
filename (str): a string representing a filename.
Returns:
bool: True if the filename is valid on Windows, False otherwise.
"""
pass
def is_linux_valid_filename(filename: str) -> bool:
"""Check if the filename is valid on Linux.
Args:
filename (str): a string representing a filename.
Returns:
bool: True if the filename is valid on Linux, False otherwise.
"""
pass
def is_darwin_valid_filename(filename: str) -> bool:
"""Check if the filename is valid on macOS.
Args:
filename (str): a string representing a filename.
Returns:
bool: True if the filename is valid on macOS, False otherwise.
"""
pass
import sys
if sys.platform == "win32":
return is_windows_valid_filename(filename)
elif sys.platform == "linux":
return is_linux_valid_filename(filename)
elif sys.platform == "darwin":
return is_darwin_valid_filename(filename)
return False