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)
|
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):
|
class RegexHeuristics(BaseModel):
|
||||||
"""
|
"""
|
||||||
Regex heuristics options for applying modifying a line using regex lines.
|
Regex heuristics options for applying modifying a line using regex lines.
|
||||||
|
|
|
@ -44,18 +44,20 @@ class Converter:
|
||||||
"""
|
"""
|
||||||
source_path = self._jekyll_posts_path
|
source_path = self._jekyll_posts_path
|
||||||
output_path = Path(self._hugo_posts_path)
|
output_path = Path(self._hugo_posts_path)
|
||||||
_, _, files = next(os.walk(source_path))
|
|
||||||
posts_converted_count = 0
|
posts_converted_count = 0
|
||||||
for file in files:
|
try:
|
||||||
source_abs_path = source_path / Path(file)
|
_, _, files = next(os.walk(source_path))
|
||||||
|
for file in files:
|
||||||
|
source_abs_path = source_path / Path(file)
|
||||||
|
|
||||||
file_reader = FileReader(str(source_abs_path))
|
file_reader = FileReader(str(source_abs_path))
|
||||||
file_writer = FileWriter(output_path.joinpath(source_abs_path.name))
|
file_writer = FileWriter(output_path.joinpath(source_abs_path.name))
|
||||||
|
|
||||||
self.markdown_converter.convert_jekyll_to_hugo(
|
self.markdown_converter.convert_jekyll_to_hugo(
|
||||||
file_reader,
|
file_reader,
|
||||||
file_writer,
|
file_writer,
|
||||||
)
|
)
|
||||||
posts_converted_count += 1
|
posts_converted_count += 1
|
||||||
|
self._logger.info(f"Converted {posts_converted_count} posts! 🚀")
|
||||||
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
|
import logging
|
||||||
|
|
||||||
from app.config import Configurator
|
from app.config import Configurator, ensure_config_exists
|
||||||
from app.converter import Converter
|
from app.converter import Converter
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Configurator
|
# Configurator
|
||||||
|
ensure_config_exists()
|
||||||
configurator = Configurator()
|
configurator = Configurator()
|
||||||
|
|
||||||
# Logging configuration
|
# Logging configuration
|
||||||
|
|
Loading…
Reference in a new issue