WarningFormatter.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 4
cts 4
cp 1
crap 1
1
"""Common classes and functions."""
2
3 1
import argparse
4 1
import logging
5
6 1
from dtb import VERSION
7
8
9 1
class HelpFormatter(argparse.HelpFormatter):
10
    """Command-line help text formatter with wider help text."""
11
12 1
    def __init__(self, *args, **kwargs):
13 1
        super().__init__(*args, max_help_position=40, **kwargs)
14
15
16 1
class WarningFormatter(logging.Formatter, object):
17
    """Displays verbose logging for level WARNING or higher."""
18
19 1
    def __init__(self, default_format, verbose_format, *args, **kwargs):
20 1
        super().__init__(*args, **kwargs)
21 1
        self.default_format = default_format
22 1
        self.verbose_format = verbose_format
23
24 1
    def format(self, record):
25
        """Python 3 hack to change the formatting style dynamically."""
26 1
        if record.levelno > logging.INFO:
27 1
            self._style._fmt = self.verbose_format  # pylint: disable=W0212
28
        else:
29 1
            self._style._fmt = self.default_format  # pylint: disable=W0212
30 1
        return super().format(record)
31
32
# Shared command-line arguments
33 1
DEBUG = argparse.ArgumentParser(add_help=False)
34 1
DEBUG.add_argument('-V', '--version', action='version', version=VERSION)
35 1
DEBUG.add_argument('-v', '--verbose', action='count', default=0,
36
                   help="enable verbose logging")
37
SHARED = {'formatter_class': HelpFormatter, 'parents': [DEBUG]}
38