This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/cli.py

29 lines
778 B
Python
Raw Normal View History

2017-03-27 09:02:05 +01:00
import logging
2017-03-29 18:26:54 +01:00
from md_pdf.args import parse_args
2017-03-29 19:16:12 +01:00
from md_pdf.exceptions import PrematureExit, BaseException
2017-03-29 18:26:54 +01:00
from md_pdf.build import build
from md_pdf.config.read import load_config
2017-03-29 18:43:35 +01:00
from md_pdf.config.validate import validate_config
2017-03-29 22:18:01 +01:00
from md_pdf.csl import check_csl, download_csl
2017-03-27 09:02:05 +01:00
FORMAT = "[%(levelname)s]: %(message)s"
def cli():
2017-03-29 18:26:54 +01:00
args = parse_args()
2017-03-29 22:19:07 +01:00
logging.basicConfig(format=FORMAT, level=logging.INFO if args.verbose else logging.NOTSET)
2017-03-29 18:26:54 +01:00
try:
2017-03-29 22:18:01 +01:00
if args.update_csl:
download_csl()
return 0
check_csl()
2017-03-29 18:26:54 +01:00
config = load_config()
2017-03-29 18:43:35 +01:00
validate_config(config)
2017-03-29 19:16:12 +01:00
build(config)
2017-03-29 18:26:54 +01:00
except PrematureExit:
return 0
2017-03-29 19:16:12 +01:00
except BaseException as e:
2017-03-29 18:26:54 +01:00
logging.error(str(e))
return 1
return 0