Skip to content

Commit

Permalink
Merge pull request #140 from tosh2230/get-uri
Browse files Browse the repository at this point in the history
func get_uri()
  • Loading branch information
tosh2230 authored Sep 26, 2023
2 parents d2df900 + 6a65831 commit edc0d79
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/stairlight/stairlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from dataclasses import asdict
from logging import getLogger
from typing import Any
from typing import Any, OrderedDict

import src.stairlight.util as sl_util
from src.stairlight.configurator import Configurator
Expand Down Expand Up @@ -196,26 +196,34 @@ def _write_map(self) -> None:

def get_templates_not_found(self) -> list[str]:
not_found: set[str] = set()

# Uris that stairlight knows
mapped_urls: list[str] = self.list_uris()
for config in self._mapping_config.Mapping:
uri: str = ""
if config.get(MappingConfigKey.TEMPLATE_SOURCE_TYPE) in [
TemplateSourceType.FILE.value,
TemplateSourceType.DBT.value,
]:
file_suffix = config.get(MappingConfigKey.File.FILE_SUFFIX)
uri = os.path.abspath(f"./{file_suffix}")
elif config.get(MappingConfigKey.TEMPLATE_SOURCE_TYPE) in [
TemplateSourceType.GCS.value,
TemplateSourceType.S3.value,
]:
uri = config.get(MappingConfigKey.Gcs.URI)

for config in self._mapping_config.Mapping:
# Uri that mapping config set
uri: str = self.get_uri(config=config)
if uri not in mapped_urls:
not_found.add(uri)

return sorted(not_found)

@staticmethod
def get_uri(config: OrderedDict[str, Any]) -> str:
uri: str = ""
if config.get(MappingConfigKey.TEMPLATE_SOURCE_TYPE) in [
TemplateSourceType.FILE.value,
TemplateSourceType.DBT.value,
]:
file_suffix = config.get(MappingConfigKey.File.FILE_SUFFIX)
uri = os.path.abspath(f"./{file_suffix}")
elif config.get(MappingConfigKey.TEMPLATE_SOURCE_TYPE) in [
TemplateSourceType.GCS.value,
TemplateSourceType.S3.value,
]:
uri = config.get(MappingConfigKey.Gcs.URI)
return uri

def init(self, prefix: str = STAIRLIGHT_CONFIG_PREFIX_DEFAULT) -> str:
"""Create Stairlight template file
Expand Down

0 comments on commit edc0d79

Please sign in to comment.