Commit a881e511fe5216efe75cf46ac70284ca8b4b1853
1 parent
1d65b0b7
Exists in
master
and in
1 other branch
- missing database aborts cleanly instead of exception.
- main added to the loggers (todo: change logging to logger)
Showing
2 changed files
with
11 additions
and
12 deletions
Show diff stats
aprendizations/learnapp.py
@@ -373,12 +373,12 @@ class LearnApp(): | @@ -373,12 +373,12 @@ class LearnApp(): | ||
373 | 373 | ||
374 | logger.info('Checking database "%s":', database) | 374 | logger.info('Checking database "%s":', database) |
375 | if not exists(database): | 375 | if not exists(database): |
376 | - raise LearnException('Database does not exist. ' | ||
377 | - 'Use "initdb-aprendizations" to create') | 376 | + msg = 'Database does not exist.' |
377 | + logger.error(msg) | ||
378 | + raise LearnException(msg) | ||
378 | 379 | ||
379 | self._engine = create_engine(f'sqlite:///{database}', future=True) | 380 | self._engine = create_engine(f'sqlite:///{database}', future=True) |
380 | 381 | ||
381 | - | ||
382 | try: | 382 | try: |
383 | query_students = select(func.count(Student.id)) | 383 | query_students = select(func.count(Student.id)) |
384 | query_topics = select(func.count(Topic.id)) | 384 | query_topics = select(func.count(Topic.id)) |
aprendizations/main.py
@@ -7,6 +7,7 @@ Setup configurations and then runs the application. | @@ -7,6 +7,7 @@ Setup configurations and then runs the application. | ||
7 | 7 | ||
8 | # python standard library | 8 | # python standard library |
9 | import argparse | 9 | import argparse |
10 | +import logging | ||
10 | import logging.config | 11 | import logging.config |
11 | from os import environ, path | 12 | from os import environ, path |
12 | import ssl | 13 | import ssl |
@@ -14,10 +15,10 @@ import sys | @@ -14,10 +15,10 @@ import sys | ||
14 | from typing import Any, Dict | 15 | from typing import Any, Dict |
15 | 16 | ||
16 | # this project | 17 | # this project |
17 | -from aprendizations.learnapp import LearnApp, DatabaseUnusableError, LearnException | ||
18 | -from aprendizations.serve import run_webserver | ||
19 | -from aprendizations.tools import load_yaml | ||
20 | -from aprendizations import APP_NAME, APP_VERSION | 18 | +from .learnapp import LearnApp, DatabaseUnusableError, LearnException |
19 | +from .serve import run_webserver | ||
20 | +from .tools import load_yaml | ||
21 | +from . import APP_NAME, APP_VERSION | ||
21 | 22 | ||
22 | 23 | ||
23 | # ---------------------------------------------------------------------------- | 24 | # ---------------------------------------------------------------------------- |
@@ -115,7 +116,7 @@ def get_logger_config(debug: bool = False) -> Any: | @@ -115,7 +116,7 @@ def get_logger_config(debug: bool = False) -> Any: | ||
115 | 'level': level, | 116 | 'level': level, |
116 | 'propagate': False, | 117 | 'propagate': False, |
117 | } for module in ['learnapp', 'models', 'factory', 'tools', 'serve', | 118 | } for module in ['learnapp', 'models', 'factory', 'tools', 'serve', |
118 | - 'questions', 'student']}) | 119 | + 'questions', 'student', 'main']}) |
119 | 120 | ||
120 | return load_yaml(config_file, default=default_config) | 121 | return load_yaml(config_file, default=default_config) |
121 | 122 | ||
@@ -197,12 +198,10 @@ def main(): | @@ -197,12 +198,10 @@ def main(): | ||
197 | sys.exit(1) | 198 | sys.exit(1) |
198 | except LearnException as exc: | 199 | except LearnException as exc: |
199 | logging.critical('Failed to start backend') | 200 | logging.critical('Failed to start backend') |
200 | - # sys.exit(1) | ||
201 | - raise | 201 | + sys.exit(1) |
202 | except Exception: | 202 | except Exception: |
203 | logging.critical('Unknown error') | 203 | logging.critical('Unknown error') |
204 | - # sys.exit(1) | ||
205 | - raise | 204 | + sys.exit(1) |
206 | else: | 205 | else: |
207 | logging.info('LearnApp started') | 206 | logging.info('LearnApp started') |
208 | 207 |