From f6faacabb0e6f33dc16b5dc159ea3262d0be3faa Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Sat, 9 May 2020 00:00:21 +0200 Subject: [PATCH] Move FatalException to errors.py --- PFERD/diva.py | 3 ++- PFERD/errors.py | 8 +++++++- PFERD/ilias/crawler.py | 3 ++- PFERD/logging.py | 6 ------ PFERD/pferd.py | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/PFERD/diva.py b/PFERD/diva.py index 636ffeb..f7f606e 100644 --- a/PFERD/diva.py +++ b/PFERD/diva.py @@ -5,7 +5,8 @@ from typing import Any, Callable, List, Optional import requests -from .logging import FatalException, PrettyLogger +from .errors import FatalException +from .logging import PrettyLogger from .organizer import Organizer from .tmp_dir import TmpDir from .transform import Transformable diff --git a/PFERD/errors.py b/PFERD/errors.py index dee3d5a..014479d 100644 --- a/PFERD/errors.py +++ b/PFERD/errors.py @@ -7,12 +7,18 @@ from typing import Any, Callable from rich.console import Console -from .logging import FatalException, PrettyLogger +from .logging import PrettyLogger LOGGER = logging.getLogger(__name__) PRETTY = PrettyLogger(LOGGER) +class FatalException(Exception): + """ + A fatal exception occurred. Recovery is not possible. + """ + + def swallow_and_print_errors(function: Callable) -> Callable: """ Decorates a function, swallows all errors, logs them and returns none if one occurred. diff --git a/PFERD/ilias/crawler.py b/PFERD/ilias/crawler.py index e58f444..0f7d4f6 100644 --- a/PFERD/ilias/crawler.py +++ b/PFERD/ilias/crawler.py @@ -14,7 +14,8 @@ from urllib.parse import (parse_qs, urlencode, urljoin, urlparse, urlsplit, import bs4 import requests -from ..logging import FatalException, PrettyLogger +from ..errors import FatalException +from ..logging import PrettyLogger from ..utils import soupify from .authenticators import IliasAuthenticator from .date_demangler import demangle_date diff --git a/PFERD/logging.py b/PFERD/logging.py index 4abe988..03b6565 100644 --- a/PFERD/logging.py +++ b/PFERD/logging.py @@ -32,12 +32,6 @@ def enable_logging(name: str = "PFERD", level: int = logging.INFO) -> None: logger.propagate = False -class FatalException(Exception): - """ - A fatal exception occurred. Recovery is not possible. - """ - - class RichLoggingHandler(logging.Handler): """ A logging handler that uses rich for highlighting diff --git a/PFERD/pferd.py b/PFERD/pferd.py index 1f9e431..d13d9d1 100644 --- a/PFERD/pferd.py +++ b/PFERD/pferd.py @@ -9,12 +9,12 @@ from typing import List, Optional, Union from .cookie_jar import CookieJar from .diva import (DivaDownloader, DivaDownloadStrategy, DivaPlaylistCrawler, diva_download_new) -from .errors import swallow_and_print_errors +from .errors import FatalException, swallow_and_print_errors from .ilias import (IliasAuthenticator, IliasCrawler, IliasDirectoryFilter, IliasDownloader, IliasDownloadStrategy, KitShibbolethAuthenticator, download_modified_or_new) from .location import Location -from .logging import FatalException, PrettyLogger +from .logging import PrettyLogger from .organizer import Organizer from .tmp_dir import TmpDir from .transform import TF, Transform, apply_transform