cli: move MetaDB checks to module

parent 2739ea22
#!/usr/bin/env python3
import argparse
import logging
import sys
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
......@@ -37,12 +35,7 @@ def main():
with LMDB(args.envdir, readonly=True) as lmdb:
lmdb.open_db(LMDB.QUERIES)
try:
MetaDatabase(lmdb, servers, create=False) # check version and servers
except NotImplementedError as exc:
logging.critical(exc)
sys.exit(1)
cli.check_metadb_servers_version(lmdb, servers)
dstream = repro.query_stream_from_disagreements(lmdb, report)
try:
......
......@@ -7,7 +7,6 @@ from multiprocessing import pool
import os
import pickle
from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple # noqa
import sys
from respdiff import cli
from respdiff.dataformat import (
......@@ -117,11 +116,7 @@ def main():
# interaction when using multiple transaction / processes, open a separate
# environment. Also, any dbs have to be opened before using MetaDatabase().
report = prepare_report(lmdb_, servers)
try:
MetaDatabase(lmdb_, servers, create=False) # check version and servers
except NotImplementedError as exc:
logging.critical(exc)
sys.exit(1)
cli.check_metadb_servers_version(lmdb_, servers)
with LMDB(args.envdir, fast=True) as lmdb_:
lmdb = lmdb_
......
......@@ -8,6 +8,7 @@ from typing import Callable, Dict, Mapping, Optional, Sequence, Tuple, Union #
from tabulate import tabulate
from .cfg import read_cfg
from .database import MetaDatabase
from .dataformat import DiffReport, FieldLabel, InvalidFileFormat, Summary
from .match import DataMismatch
from .stats import SummaryStatistics
......@@ -128,6 +129,14 @@ def get_datafile(args: Namespace, key: str = 'datafile', check_exists: bool = Tr
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(
description: str,
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