-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea5864c
commit 86d9ddc
Showing
72 changed files
with
4,921 additions
and
2,949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from typing import Optional, Union | ||
import traceback | ||
|
||
from supervisely import logger | ||
from supervisely import ProjectMeta | ||
|
||
|
||
class CustomException(Exception): | ||
def __init__( | ||
self, message: str, error: Optional[Exception] = None, extra: Optional[dict] = None | ||
): | ||
super().__init__(message) | ||
self.message = message | ||
self.error = error | ||
self.extra = extra | ||
|
||
def __str__(self): | ||
return self.message | ||
|
||
def log(self): | ||
exc_info = ( | ||
traceback.format_tb(self.error.__traceback__) | ||
if self.error | ||
else traceback.format_tb(self.__traceback__) | ||
) | ||
logger.error(self.message, exc_info=exc_info, extra=self.extra) | ||
|
||
|
||
class ActionNotFoundError(CustomException): | ||
def __init__(self, action_name: str, extra: Optional[dict] = {}): | ||
self.action_name = action_name | ||
extra["action_name"] = action_name | ||
super().__init__("Action not found", extra=extra) | ||
|
||
|
||
class CreateLayerError(CustomException): | ||
def __init__(self, action_name: str, error: Exception, extra: Optional[dict] = {}): | ||
self.action_name = action_name | ||
extra["action_name"] = action_name | ||
super().__init__(f"Error creating Layer", error=error, extra=extra) | ||
|
||
|
||
class LayerNotFoundError(CustomException): | ||
def __init__(self, layer_id: str, extra: Optional[dict] = {}): | ||
self.layer_id = layer_id | ||
extra["layer_id"] = layer_id | ||
super().__init__("Layer not found", extra=extra) | ||
|
||
|
||
class CreateNodeError(CustomException): | ||
def __init__(self, layer_name, error: Exception, extra: Optional[dict] = {}): | ||
self.layer_name = layer_name | ||
extra["layer_name"] = layer_name | ||
super().__init__(f"Error creating Node", error=error, extra=extra) | ||
|
||
|
||
class UpdateMetaError(CustomException): | ||
def __init__( | ||
self, | ||
layer_name: str, | ||
project_meta: ProjectMeta, | ||
error: Exception, | ||
extra: Optional[dict] = {}, | ||
): | ||
self.layer_name = layer_name | ||
self.project_meta = project_meta | ||
extra["layer_name"] = layer_name | ||
extra["project_meta"] = project_meta.to_json() | ||
super().__init__( | ||
f"Error updating project meta", | ||
error=error, | ||
extra=extra, | ||
) | ||
|
||
|
||
class GraphCalculationError(CustomException): | ||
def __init__( | ||
self, | ||
dtl_json: list, | ||
error: Exception, | ||
layer_name: Optional[str] = "", | ||
extra: Optional[dict] = {}, | ||
): | ||
extra["dtl_json"] = dtl_json | ||
extra["layer_name"] = layer_name | ||
super().__init__( | ||
"Error performing transformations", | ||
error=error, | ||
extra=extra, | ||
) | ||
|
||
|
||
class BadSettingsError(CustomException): | ||
def __init__( | ||
self, | ||
layer_name: str, | ||
settings_json: dict, | ||
error: Exception = None, | ||
extra: Optional[dict] = {}, | ||
): | ||
extra["layer_name"] = layer_name | ||
extra["settings"] = settings_json | ||
super().__init__("Bad settings", error, extra=extra) | ||
|
||
|
||
def handle_exception(func): | ||
"""Decorator to log exception and silence it""" | ||
|
||
def inner(*args, **kwargs): | ||
try: | ||
return func(*args, **kwargs) | ||
except CustomException as e: | ||
e.log() | ||
except Exception as e: | ||
logger.error("Unexpected error", exc_info=traceback.format_exc()) | ||
|
||
return inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
import shutil | ||
import os | ||
import threading | ||
import time | ||
from supervisely import Application | ||
|
||
from src.ui.ui import layout | ||
from src.ui.tabs.configure import update_metas, update_nodes | ||
from src.ui.tabs.json_preview import load_json | ||
import src.globals as g | ||
|
||
shutil.rmtree(g.STATIC_DIR, ignore_errors=True) | ||
os.mkdir(g.STATIC_DIR) | ||
app = Application(layout=layout, static_dir=g.STATIC_DIR) | ||
|
||
|
||
def _update_f(): | ||
while True: | ||
updates = [] | ||
while not g.update_queue.empty(): | ||
updates.append(g.update_queue.get()) | ||
if len(updates) == 0: | ||
time.sleep(0.1) | ||
continue | ||
try: | ||
if "load_json" in updates: | ||
load_json() | ||
elif "nodes" in updates: | ||
update_nodes() | ||
else: | ||
update_metas() | ||
finally: | ||
for _ in range(len(updates)): | ||
g.update_queue.task_done() | ||
time.sleep(0.1) | ||
|
||
|
||
update_loop = threading.Thread( | ||
target=_update_f, | ||
name="App update loop", | ||
daemon=True, | ||
) | ||
|
||
update_loop.start() |
Oops, something went wrong.