-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path__init__.py
More file actions
217 lines (183 loc) · 7.21 KB
/
__init__.py
File metadata and controls
217 lines (183 loc) · 7.21 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import logging
import os
import sys
from logging import Formatter
from logging.handlers import RotatingFileHandler
from os.path import expanduser
from lib.core.config import Config
from lib.core.enums import ApprovalStatus
from lib.core.enums import FolderStatus
from lib.core.enums import ImageQuality
from lib.core.enums import ProjectStatus
from lib.core.enums import ProjectType
from lib.core.enums import StepsType
from lib.core.enums import TrainingStatus
from lib.core.enums import UploadState
from lib.core.enums import UserRole
CONFIG = Config()
BACKEND_URL = "https://api.superannotate.com"
HOME_PATH = expanduser("~/.superannotate")
CONFIG_JSON_PATH = f"{HOME_PATH}/config.json"
CONFIG_INI_PATH = f"{HOME_PATH}/config.ini"
CONFIG_JSON_FILE_LOCATION = CONFIG_JSON_PATH
CONFIG_INI_FILE_LOCATION = CONFIG_INI_PATH
LOG_FILE_LOCATION = f"{HOME_PATH}/logs"
DEFAULT_LOGGING_LEVEL = "INFO"
_loggers = {}
def setup_logging(level=DEFAULT_LOGGING_LEVEL, file_path=LOG_FILE_LOCATION):
logger = logging.getLogger("sa")
for handler in logger.handlers[:]: # remove all old handlers
logger.removeHandler(handler)
logger.propagate = False
logger.setLevel(level)
# Separate handlers for different log levels
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.DEBUG)
stdout_handler.addFilter(lambda record: record.levelno < logging.WARNING)
stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.setLevel(logging.WARNING)
formatter = Formatter("SA-PYTHON-SDK - %(levelname)s - %(message)s")
stdout_handler.setFormatter(formatter)
stderr_handler.setFormatter(formatter)
logger.addHandler(stdout_handler)
logger.addHandler(stderr_handler)
try:
os.makedirs(file_path, exist_ok=True)
log_file_path = os.path.join(file_path, "sa.log")
file_handler = RotatingFileHandler(
log_file_path,
maxBytes=5 * 1024 * 1024,
backupCount=5,
mode="a",
)
file_formatter = Formatter(
"SA-PYTHON-SDK - %(levelname)s - %(asctime)s - %(message)s"
)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
except OSError as e:
logger.debug(e)
DEFAULT_IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "tif", "tiff", "webp", "bmp"]
DEFAULT_FILE_EXCLUDE_PATTERNS = ["___save.png", "___fuse.png"]
DEFAULT_VIDEO_EXTENSIONS = ["mp4", "avi", "mov", "webm", "flv", "mpg", "ogg"]
VECTOR_ANNOTATION_POSTFIX = "___objects.json"
PIXEL_ANNOTATION_POSTFIX = "___pixel.json"
ANNOTATION_MASK_POSTFIX = "___save.png"
ATTACHED_VIDEO_ANNOTATION_POSTFIX = ".json"
SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES = set('/\\:*?"<>|“')
MAX_PIXEL_RESOLUTION = 4_000_000
MAX_VECTOR_RESOLUTION = 100_000_000
MAX_IMAGE_SIZE = 100 * 1024 * 1024 # 100 MB limit
TOKEN_UUID = "token"
ALREADY_EXISTING_FILES_WARNING = (
"{} already existing file(s) found that won't be uploaded."
)
ATTACHING_FILES_MESSAGE = "Attaching {} file(s) to project {}."
ATTACHING_UPLOAD_STATE_ERROR = "You cannot attach URLs in this type of project. Please attach it in an external storage project."
UPLOADING_UPLOAD_STATE_ERROR = "You cannot upload files in this type of project. Please upload it in an basic storage project."
INVALID_PROJECT_TYPE_TO_PROCESS = "The function does not support projects of type {}."
DEPRECATED_VIDEO_PROJECTS_MESSAGE = (
"The function does not support projects containing videos attached with URLs"
)
DEPRECATED_DOCUMENT_PROJECTS_MESSAGE = (
"The function does not support projects containing documents attached with URLs"
)
DEPRECATED_PROJECTS_MESSAGE = (
"The function does not support projects containing items attached with URLs"
)
LIMITED_FUNCTIONS = {
ProjectType.VIDEO: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
ProjectType.DOCUMENT: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
ProjectType.POINT_CLOUD: DEPRECATED_PROJECTS_MESSAGE,
ProjectType.TILED: DEPRECATED_PROJECTS_MESSAGE,
}
METADATA_DEPRICATED_FOR_PIXEL = (
"custom_metadata field is not supported for project type Pixel."
)
DEPRICATED_DOCUMENT_VIDEO_MESSAGE = "The function does not support projects containing videos / documents attached with URLs"
UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE = "The number of items you want to upload exceeds the limit of 50 000 items per folder."
UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to upload exceeds the limit of 500 000 items per project."
UPLOAD_USER_LIMIT_ERROR_MESSAGE = "The number of items you want to upload exceeds the limit of your subscription plan."
ATTACH_FOLDER_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of 50 000 items per folder."
ATTACH_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of 500 000 items per project."
ATTACH_USER_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of your subscription plan."
COPY_FOLDER_LIMIT_ERROR_MESSAGE = (
"The number of items you want to copy exceeds the limit of 50 000 items per folder."
)
COPY_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to copy exceeds the limit of 500 000 items per project."
COPY_SUPER_LIMIT_ERROR_MESSAGE = (
"The number of items you want to copy exceeds the limit of your subscription plan."
)
MOVE_FOLDER_LIMIT_ERROR_MESSAGE = (
"The number of items you want to move exceeds the limit of 50 000 items per folder."
)
MOVE_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 500 000 items per project."
PACKAGE_VERSION_INFO_MESSAGE = (
"Development version {} of SuperAnnotate SDK is being used."
)
PACKAGE_VERSION_MAJOR_UPGRADE = (
"There is a major upgrade of SuperAnnotate Python SDK available on PyPI. "
"We recommend upgrading. Run 'pip install --upgrade superannotate' to "
"upgrade from your version {} to {}."
)
PACKAGE_VERSION_UPGRADE = (
"There is a newer version of SuperAnnotate Python SDK available on PyPI."
" Run 'pip install --upgrade superannotate' to"
" upgrade from your version {} to {}"
)
USE_VALIDATE_MESSAGE = (
"Use the validate_annotations function to discover the possible reason(s) for "
"which an annotation is invalid."
)
INVALID_JSON_MESSAGE = "Invalid json"
PROJECT_SETTINGS_VALID_ATTRIBUTES = [
"Brightness",
"Fill",
"Contrast",
"ShowLabels",
"ShowComments",
"Image",
"Lines",
"AnnotatorFinish",
"PointSize",
"FontSize",
"WorkflowEnable",
"ClassChange",
"ShowEntropy",
"UploadImages",
"DeleteImages",
"Download",
"RunPredictions",
"RunSegmentations",
"ImageQuality",
"ImageAutoAssignCount",
"FrameMode",
"FrameRate",
"JumpBackward",
"JumpForward",
"UploadFileType",
"Tokenization",
"ImageAutoAssignEnable",
"TemplateState",
"CategorizeItems",
]
__alL__ = (
FolderStatus,
ProjectStatus,
ProjectType,
StepsType,
UserRole,
UploadState,
TrainingStatus,
ImageQuality,
ApprovalStatus,
CONFIG_JSON_FILE_LOCATION,
CONFIG_INI_FILE_LOCATION,
BACKEND_URL,
DEFAULT_IMAGE_EXTENSIONS,
DEFAULT_FILE_EXCLUDE_PATTERNS,
DEFAULT_VIDEO_EXTENSIONS,
MAX_IMAGE_SIZE,
MAX_VECTOR_RESOLUTION,
MAX_PIXEL_RESOLUTION,
)