Skip to content

Commit 61b829f

Browse files
committed
Merge
2 parents 1c7fe0c + c482d3a commit 61b829f

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import logging
2-
31
from lib.infrastructure.controller import Controller
42
from lib.infrastructure.repositories import ConfigRepository
53

64

7-
logger = logging.getLogger()
8-
9-
105
class BaseInterfaceFacade:
116
def __init__(self):
127
self._config_path = None
@@ -15,6 +10,7 @@ def __init__(self):
1510
def controller(self):
1611
if not ConfigRepository().get_one("token"):
1712
raise Exception("Config does not exists!")
13+
controller = Controller.get_instance()
1814
if self._config_path:
19-
return Controller(logger, self._config_path)
20-
return Controller(logger)
15+
controller.init(self._config_path)
16+
return controller

src/superannotate/lib/app/interface/cli_interface.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import logging
32
import os
43
import sys
54
import tempfile
@@ -24,8 +23,8 @@
2423
from lib.infrastructure.controller import Controller
2524
from lib.infrastructure.repositories import ConfigRepository
2625

27-
logger = logging.getLogger()
28-
controller = Controller(logger)
26+
27+
controller = Controller.get_instance()
2928

3029

3130
class CLIFacade(BaseInterfaceFacade):

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
from tqdm import tqdm
5454

5555

56+
controller = Controller.get_instance()
5657
logger = logging.getLogger("root")
57-
controller = Controller(logger)
5858

5959

6060
@validate_arguments
@@ -67,7 +67,7 @@ def init(path_to_config_json: str):
6767
:param path_to_config_json: Location to config JSON file
6868
:type path_to_config_json: str or Path
6969
"""
70-
# global controller
70+
global controller
7171
controller.init(path_to_config_json)
7272

7373

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import logging
2-
31
import lib.core as constances
42
from lib.app.helpers import extract_project_folder
53
from lib.core.enums import ProjectType
64
from lib.infrastructure.controller import Controller
75

8-
controller = Controller(logger=logging.getLogger())
6+
controller = Controller.get_instance()
97

108

119
def get_project_name(project):

src/superannotate/lib/infrastructure/controller.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import io
3+
import logging
34
from pathlib import Path
45
from typing import Iterable
56
from typing import List
@@ -43,13 +44,14 @@ def __call__(cls, *args, **kwargs):
4344
def get_instance(cls):
4445
if cls._instances:
4546
return cls._instances[cls]
47+
return cls()
4648

4749

4850
class BaseController(metaclass=SingleInstanceMetaClass):
49-
def __init__(self, logger, config_path=constances.CONFIG_FILE_LOCATION):
51+
def __init__(self, config_path=constances.CONFIG_FILE_LOCATION):
5052
self._config_path = None
5153
self._backend_client = None
52-
self._logger = logger
54+
self._logger = logging.getLogger("root")
5355
self._s3_upload_auth_data = None
5456
self._projects = None
5557
self._folders = None
@@ -93,17 +95,17 @@ def init(self, config_path):
9395
self._backend_client.api_url = main_endpoint
9496
self._backend_client._auth_token = token
9597
self._backend_client.get_session.cache_clear()
96-
token = self.configs.get_one("token").value
97-
self.validate_token(token)
98-
self._team_id = int(token.split("=")[-1])
98+
if self.is_valid_token(token):
99+
self._team_id = int(token.split("=")[-1])
99100
self._team = None
100101

101102
@staticmethod
102-
def validate_token(token: str):
103+
def is_valid_token(token: str):
103104
try:
104-
return int(token.split("=")[-1])
105+
int(token.split("=")[-1])
106+
return True
105107
except Exception:
106-
raise AppException("Invalid token.")
108+
return False
107109

108110
@property
109111
def config_path(self):
@@ -181,6 +183,8 @@ def configs(self):
181183
@property
182184
def team_id(self) -> int:
183185
if not self._team_id:
186+
if not self.is_valid_token(self.configs.get_one("token").value):
187+
raise AppException("Invalid token.")
184188
self._team_id = int(self.configs.get_one("token").value.split("=")[-1])
185189
return self._team_id
186190

@@ -208,8 +212,8 @@ def s3_repo(self):
208212

209213

210214
class Controller(BaseController):
211-
def __init__(self, logger, config_path=constances.CONFIG_FILE_LOCATION):
212-
super().__init__(logger, config_path)
215+
def __init__(self, config_path=constances.CONFIG_FILE_LOCATION):
216+
super().__init__(config_path)
213217
self._team = None
214218

215219
def _get_project(self, name: str):

0 commit comments

Comments
 (0)