aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-04-27 17:41:14 +0200
committerWolfgang Müller2021-04-28 20:15:53 +0200
commit5213365b42640d5f5dcba5adde071100d49fe2b0 (patch)
treec6df9f2e939fdaae8bce209a02c076f18cf846e3
parentf994851c472d097a4cd34da42abc16bea30dc4c6 (diff)
downloadquarg-5213365b42640d5f5dcba5adde071100d49fe2b0.tar.gz
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.
-rw-r--r--quarg/main.py15
-rw-r--r--quarg/utils.py15
2 files changed, 16 insertions, 14 deletions
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