From 5213365b42640d5f5dcba5adde071100d49fe2b0 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 27 Apr 2021 17:41:14 +0200 Subject: Split errx and parse_isodate out into utils.py We're going to need this for an upcoming commit that moves all argparse.Action classes to its own file. --- quarg/main.py | 15 +-------------- quarg/utils.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 quarg/utils.py diff --git a/quarg/main.py b/quarg/main.py index 2973a2a..541c4d6 100644 --- a/quarg/main.py +++ b/quarg/main.py @@ -5,7 +5,6 @@ import sys from abc import ABCMeta, abstractmethod from timeit import default_timer as timer -import dateutil.parser import dateutil.relativedelta from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -14,9 +13,7 @@ import quarg.database.filters as filters from quarg.database.tables import Backlog, Buffer, Network, QuasselUser, Sender from quarg.quassel.formatter import format_from from quarg.quassel.types import BufferType, MessageFlag, MessageType - -def errx(msg): - sys.exit(f'quarg: {msg}') +from quarg.utils import errx, parse_isodate # TODO Find out what to do about passing INVALID or GROUP as BufferType # TODO Find out what to do about passing various message flags @@ -51,16 +48,6 @@ class ParseBufferType(ParseEnum): def enumclass(self): return BufferType -def parse_isodate(date): - try: - parsed = dateutil.parser.isoparse(date) - except ValueError as err: - errx(f'isoparse: invalid date format \'{date}\', {err}') - except OverflowError as err: - errx(f'isoparse: date overflows: \'{date}\'') - - return parsed - # FIXME make sure pylint disables are actually still needed everywhere class ParseDate(argparse.Action): diff --git a/quarg/utils.py b/quarg/utils.py new file mode 100644 index 0000000..7fa270e --- /dev/null +++ b/quarg/utils.py @@ -0,0 +1,15 @@ +import sys +import dateutil.parser + +def errx(msg): + sys.exit(f'quarg: {msg}') + +def parse_isodate(date): + try: + parsed = dateutil.parser.isoparse(date) + except ValueError as err: + errx(f'isoparse: invalid date format \'{date}\', {err}') + except OverflowError as err: + errx(f'isoparse: date overflows: \'{date}\'') + + return parsed -- cgit v1.2.3-2-gb3c3