Setup variable verbosity
This commit is contained in:
parent
9a52015397
commit
c1a3947359
5 changed files with 28 additions and 5 deletions
|
@ -3,7 +3,7 @@ import argparse
|
|||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-v", "--verbose", help="Display verbose output", action="store_true")
|
||||
parser.add_argument("-v", "--verbose", help="Display verbose output", action="count", default=0)
|
||||
parser.add_argument("--update-csl", help="Update CSL files", action="store_true")
|
||||
parser.add_help = True
|
||||
return parser.parse_args()
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import logging
|
||||
from md_pdf.args import parse_args
|
||||
from md_pdf.exceptions import PrematureExit, BaseException
|
||||
from md_pdf.logging import set_verbosity
|
||||
from md_pdf.build import build
|
||||
from md_pdf.config.read import load_config
|
||||
from md_pdf.config.validate import validate_config
|
||||
from md_pdf.csl import check_csl, download_csl
|
||||
|
||||
FORMAT = "[%(levelname)s]: %(message)s"
|
||||
|
||||
|
||||
def cli():
|
||||
args = parse_args()
|
||||
logging.basicConfig(format=FORMAT, level=logging.WARN if args.verbose else logging.INFO)
|
||||
set_verbosity(args)
|
||||
try:
|
||||
if args.update_csl:
|
||||
download_csl()
|
||||
|
|
|
@ -69,7 +69,6 @@ def validate_context(config):
|
|||
|
||||
|
||||
def validate_config(config):
|
||||
logger.info("Validating Config...")
|
||||
for validator in [
|
||||
check_required_keys,
|
||||
test_input,
|
||||
|
|
18
md_pdf/logging.py
Normal file
18
md_pdf/logging.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import logging
|
||||
from md_pdf.utils import safe_list_get
|
||||
|
||||
|
||||
FORMAT = "[%(levelname)s]: %(message)s"
|
||||
LOG_LEVELS = [
|
||||
logging.WARN,
|
||||
logging.INFO,
|
||||
logging.DEBUG,
|
||||
logging.NOTSET
|
||||
]
|
||||
|
||||
|
||||
def set_verbosity(args):
|
||||
level = min(args.verbose, len(LOG_LEVELS) - 1)
|
||||
verbosity = safe_list_get(LOG_LEVELS, level, logging.NOTSET)
|
||||
logging.basicConfig(format=FORMAT, level=verbosity)
|
||||
|
|
@ -12,3 +12,10 @@ def remove_dir(dir):
|
|||
os.rmdir(dir)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def safe_list_get(l, idx, default):
|
||||
try:
|
||||
return l[idx]
|
||||
except IndexError:
|
||||
return default
|
||||
|
|
Reference in a new issue