add better error handling for when source path does not exists
This commit is contained in:
parent
46d83824f6
commit
603fb15bb4
3 changed files with 25 additions and 13 deletions
|
@ -13,6 +13,15 @@ def yaml_config_settings_source(settings: BaseSettings):
|
|||
return yaml.safe_load(fh)
|
||||
|
||||
|
||||
def ensure_config_exists():
|
||||
"""
|
||||
Ensure config file exist at the path specified in the environment variable CONFIG_PATH.
|
||||
"""
|
||||
path = os.getenv("CONFIG_PATH", "config.yaml")
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(f"Config file not found at {path}")
|
||||
|
||||
|
||||
class RegexHeuristics(BaseModel):
|
||||
"""
|
||||
Regex heuristics options for applying modifying a line using regex lines.
|
||||
|
|
|
@ -44,8 +44,9 @@ class Converter:
|
|||
"""
|
||||
source_path = self._jekyll_posts_path
|
||||
output_path = Path(self._hugo_posts_path)
|
||||
_, _, files = next(os.walk(source_path))
|
||||
posts_converted_count = 0
|
||||
try:
|
||||
_, _, files = next(os.walk(source_path))
|
||||
for file in files:
|
||||
source_abs_path = source_path / Path(file)
|
||||
|
||||
|
@ -57,5 +58,6 @@ class Converter:
|
|||
file_writer,
|
||||
)
|
||||
posts_converted_count += 1
|
||||
|
||||
self._logger.info(f"Converted {posts_converted_count} posts! 🚀")
|
||||
except StopIteration:
|
||||
self._logger.fatal(f"Source path {source_path} does not exist!")
|
||||
|
|
3
main.py
3
main.py
|
@ -1,11 +1,12 @@
|
|||
import logging
|
||||
|
||||
from app.config import Configurator
|
||||
from app.config import Configurator, ensure_config_exists
|
||||
from app.converter import Converter
|
||||
|
||||
|
||||
def main():
|
||||
# Configurator
|
||||
ensure_config_exists()
|
||||
configurator = Configurator()
|
||||
|
||||
# Logging configuration
|
||||
|
|
Loading…
Reference in a new issue