cli: move MetaDB checks to module

parent 2739ea22
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import logging
import sys
from respdiff import cli, repro, sendrecv from respdiff import cli, repro, sendrecv
from respdiff.database import DNSRepliesFactory, LMDB, MetaDatabase from respdiff.database import DNSRepliesFactory, LMDB
from respdiff.dataformat import DiffReport, ReproData from respdiff.dataformat import DiffReport, ReproData
...@@ -37,12 +35,7 @@ def main(): ...@@ -37,12 +35,7 @@ def main():
with LMDB(args.envdir, readonly=True) as lmdb: with LMDB(args.envdir, readonly=True) as lmdb:
lmdb.open_db(LMDB.QUERIES) lmdb.open_db(LMDB.QUERIES)
cli.check_metadb_servers_version(lmdb, servers)
try:
MetaDatabase(lmdb, servers, create=False) # check version and servers
except NotImplementedError as exc:
logging.critical(exc)
sys.exit(1)
dstream = repro.query_stream_from_disagreements(lmdb, report) dstream = repro.query_stream_from_disagreements(lmdb, report)
try: try:
......
...@@ -7,7 +7,6 @@ from multiprocessing import pool ...@@ -7,7 +7,6 @@ from multiprocessing import pool
import os import os
import pickle import pickle
from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple # noqa from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple # noqa
import sys
from respdiff import cli from respdiff import cli
from respdiff.dataformat import ( from respdiff.dataformat import (
...@@ -117,11 +116,7 @@ def main(): ...@@ -117,11 +116,7 @@ def main():
# interaction when using multiple transaction / processes, open a separate # interaction when using multiple transaction / processes, open a separate
# environment. Also, any dbs have to be opened before using MetaDatabase(). # environment. Also, any dbs have to be opened before using MetaDatabase().
report = prepare_report(lmdb_, servers) report = prepare_report(lmdb_, servers)
try: cli.check_metadb_servers_version(lmdb_, servers)
MetaDatabase(lmdb_, servers, create=False) # check version and servers
except NotImplementedError as exc:
logging.critical(exc)
sys.exit(1)
with LMDB(args.envdir, fast=True) as lmdb_: with LMDB(args.envdir, fast=True) as lmdb_:
lmdb = lmdb_ lmdb = lmdb_
......
...@@ -8,6 +8,7 @@ from typing import Callable, Dict, Mapping, Optional, Sequence, Tuple, Union # ...@@ -8,6 +8,7 @@ from typing import Callable, Dict, Mapping, Optional, Sequence, Tuple, Union #
from tabulate import tabulate from tabulate import tabulate
from .cfg import read_cfg from .cfg import read_cfg
from .database import MetaDatabase
from .dataformat import DiffReport, FieldLabel, InvalidFileFormat, Summary from .dataformat import DiffReport, FieldLabel, InvalidFileFormat, Summary
from .match import DataMismatch from .match import DataMismatch
from .stats import SummaryStatistics from .stats import SummaryStatistics
...@@ -128,6 +129,14 @@ def get_datafile(args: Namespace, key: str = 'datafile', check_exists: bool = Tr ...@@ -128,6 +129,14 @@ def get_datafile(args: Namespace, key: str = 'datafile', check_exists: bool = Tr
return datafile return datafile
def check_metadb_servers_version(lmdb, servers: Sequence[str]) -> None:
try:
MetaDatabase(lmdb, servers, create=False) # check version and servers
except NotImplementedError as exc:
logging.critical(str(exc))
sys.exit(1)
def format_stats_line( def format_stats_line(
description: str, description: str,
number: int, number: int,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment