Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions getdeck/fetch/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
select_deck_fetch_behavior,
)
from getdeck.fetch.types import DataAux
from getdeck.fetch.utils import get_path_and_name
from getdeck.fetch.utils import detect_deckfile, get_path_and_name
from getdeck.deckfile.file import DeckfileDeck

from getdeck.deckfile.selector import deckfile_selector
Expand Down Expand Up @@ -83,20 +83,28 @@ def fetch_data(
delete returned DataAux to clean up temporary resources
"""

logger.info(f"Reading Deckfile from: {location}")
# info
display_location = location
if display_location == ".":
display_location = detect_deckfile()

logger.info(f"Reading Deckfile: {display_location}")

# fetch deck
data_aux = DataAux()
data_aux = _fetch_deck(data_aux=data_aux, location=location)

# validate
file = os.path.join(data_aux.deckfile_aux.path, data_aux.deckfile_aux.name)
if not os.path.isfile(file):
file_detected = os.path.join(data_aux.deckfile_aux.path, data_aux.deckfile_aux.name)
if not os.path.isfile(file_detected):
logger.debug(f"Absolute file location: {file_detected}")
del data_aux
raise RuntimeError(f"Cannot identify Deckfile at location: '{location}'")
raise RuntimeError(f"Cannot identify Deckfile at location: {display_location}")

deckfile = deckfile_selector.get(file)
deckfile = deckfile_selector.get(file_detected)
data_aux.deckfile = deckfile

# parse + fetch sources
# fetch sources
if fetch_sources:
deck = deckfile.get_deck(deck_name)
source_auxs = _fetch_sources(deck=deck)
Expand Down
23 changes: 13 additions & 10 deletions getdeck/fetch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from getdeck import configuration


def detect_deckfile() -> Optional[str]:
for extension in [".yaml", ".yml"]:
name = os.path.splitext(configuration.DECKFILE_FILE)[0] + extension
location = os.path.join(os.getcwd(), name)
if os.path.isfile(location):
return name
return None


def get_path_and_name(location: Optional[str]) -> Tuple[str, str]:
# None
if location is None:
Expand All @@ -15,16 +24,10 @@ def get_path_and_name(location: Optional[str]) -> Tuple[str, str]:

# ".", ""
if location in [".", ""]:
for extension in [".yaml", ".yml"]:
location_default = os.path.join(
os.getcwd(),
os.path.splitext(configuration.DECKFILE_FILE)[0] + extension,
)
if os.path.isfile(location_default):
location = location_default
break
else:
location = os.path.join(os.getcwd(), configuration.DECKFILE_FILE)
name = detect_deckfile()
if not name:
name = configuration.DECKFILE_FILE
location = os.path.join(os.getcwd(), name)

name = os.path.basename(location)
dirname = os.path.dirname(location)
Expand Down