-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BI-5486: Add data type of conn-icons (#491)
* Add data type of conn-icons * Add logging * Add error handling * Add error handling * Issue fixes * Issue fixes
- Loading branch information
Showing
22 changed files
with
258 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import base64 | ||
from importlib.abc import Traversable | ||
from importlib.resources import as_file | ||
import logging | ||
from typing import ( | ||
ClassVar, | ||
Optional, | ||
final, | ||
) | ||
|
||
import attr | ||
|
||
from dl_i18n.localizer_base import ( | ||
Localizer, | ||
Translatable, | ||
) | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@attr.s | ||
class ConnectionInfoProvider: | ||
title_translatable: ClassVar[Translatable] | ||
alias: ClassVar[Optional[str]] = None | ||
icon_data_standard: Optional[bytes] = attr.ib(default=None) | ||
icon_data_nav: Optional[bytes] = attr.ib(default=None) | ||
icon_data_standard_filepath: Optional[Traversable] = attr.ib(default=None) | ||
icon_data_nav_filepath: Optional[Traversable] = attr.ib(default=None) | ||
|
||
@classmethod | ||
@final | ||
def get_title(cls, localizer: Localizer) -> str: | ||
return localizer.translate(cls.title_translatable) | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard = self.get_icon_file(self.icon_data_standard_filepath) | ||
self.icon_data_nav = self.get_icon_file(self.icon_data_nav_filepath) | ||
|
||
def get_icon_file(self, filepath: Traversable | None) -> bytes | None: | ||
if not filepath: | ||
return None | ||
try: | ||
with as_file(filepath) as file: | ||
with open(file, "rb") as icon_file: | ||
return base64.b64encode(icon_file.read()) | ||
except Exception: | ||
LOGGER.info(f"Connector icon reading by path {str(filepath)} failed") | ||
return None |
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
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_bigquery/dl_connector_bigquery/api/connection_info.py
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,7 +1,18 @@ | ||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_bigquery.api.i18n.localizer import Translatable | ||
from dl_connector_bigquery.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class BigQueryConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-bigquery") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("bigquery.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("bigquery.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_bitrix_gds/dl_connector_bitrix_gds/api/connection_info.py
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,9 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_bitrix_gds.api.i18n.localizer import Translatable | ||
from dl_connector_bitrix_gds.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class BitrixGDSConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-bitrix") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("bitrix24.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("bitrix24.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_bundle_chs3/dl_connector_bundle_chs3/chs3_gsheets/api/connection_info.py
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,9 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_bundle_chs3.chs3_base.api.i18n.localizer import Translatable | ||
from dl_connector_bundle_chs3.chs3_gsheets.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class GSheetsFileS3ConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-gsheets_v2") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("gsheets.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("gsheets.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_bundle_chs3/dl_connector_bundle_chs3/chs3_yadocs/api/connection_info.py
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,9 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_bundle_chs3.chs3_base.api.i18n.localizer import Translatable | ||
from dl_connector_bundle_chs3.chs3_yadocs.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class YaDocsFileS3ConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-yadocs") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("yadocs.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("yadocs.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_bundle_chs3/dl_connector_bundle_chs3/file/api/connection_info.py
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,9 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_bundle_chs3.chs3_base.api.i18n.localizer import Translatable | ||
from dl_connector_bundle_chs3.file.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class FileS3ConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-file") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("file.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("file.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_chyt/dl_connector_chyt/api/connection_info.py
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,9 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_chyt.api.i18n.localizer import Translatable | ||
from dl_connector_chyt.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class CHYTConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-chyt") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("chyt.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("chyt.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_clickhouse/dl_connector_clickhouse/api/connection_info.py
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,7 +1,18 @@ | ||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_clickhouse.api.i18n.localizer import Translatable | ||
from dl_connector_clickhouse.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class ClickHouseConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-clickhouse") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("clickhouse.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("clickhouse.svg") | ||
super().__attrs_post_init__() |
11 changes: 11 additions & 0 deletions
11
lib/dl_connector_greenplum/dl_connector_greenplum/api/connection_info.py
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,7 +1,18 @@ | ||
from importlib.resources import files | ||
|
||
from dl_api_connector.connection_info import ConnectionInfoProvider | ||
|
||
from dl_connector_greenplum.api.i18n.localizer import Translatable | ||
from dl_connector_greenplum.assets.icons import ( | ||
nav, | ||
standard, | ||
) | ||
|
||
|
||
class GreenplumConnectionInfoProvider(ConnectionInfoProvider): | ||
title_translatable = Translatable("label_connector-greenplum") | ||
|
||
def __attrs_post_init__(self) -> None: | ||
self.icon_data_standard_filepath = files(standard).joinpath("greenplum.svg") | ||
self.icon_data_nav_filepath = files(nav).joinpath("greenplum.svg") | ||
super().__attrs_post_init__() |
Oops, something went wrong.