Specify output formats
This commit is contained in:
parent
5ab9211958
commit
1a60c4c1bc
5 changed files with 35 additions and 10 deletions
|
@ -6,9 +6,11 @@ from md_pdf.build.pdf import export_pdf
|
|||
import os
|
||||
|
||||
|
||||
def build(args, config):
|
||||
def build(config):
|
||||
data = read_files(os.path.join(WORKING_DIR, '*.md'))
|
||||
doc = build_document(data, os.path.join(WORKING_DIR, 'bib.yaml'))
|
||||
if 'html' in config.output_formats:
|
||||
output_html(doc, os.path.join(WORKING_DIR, 'out'))
|
||||
if 'pdf' in config.output_formats:
|
||||
render_cover()
|
||||
export_pdf(doc, os.path.join(WORKING_DIR, 'out'))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import logging
|
||||
from md_pdf.args import parse_args
|
||||
from md_pdf.exceptions import PrematureExit
|
||||
from md_pdf.exceptions import PrematureExit, BaseException
|
||||
from md_pdf.build import build
|
||||
from md_pdf.config.read import load_config
|
||||
from md_pdf.config.validate import validate_config
|
||||
|
@ -15,10 +15,10 @@ def cli():
|
|||
try:
|
||||
config = load_config()
|
||||
validate_config(config)
|
||||
build(args, config)
|
||||
build(config)
|
||||
except PrematureExit:
|
||||
return 0
|
||||
except Exception as e:
|
||||
except BaseException as e:
|
||||
logging.error(str(e))
|
||||
return 1
|
||||
return 0
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from md_pdf.exceptions import ConfigValidationException
|
||||
import os
|
||||
|
||||
|
||||
REQUIRED_KEYS = [
|
||||
'output',
|
||||
'output_dir',
|
||||
'output_formats',
|
||||
'input'
|
||||
]
|
||||
|
||||
|
@ -13,7 +15,19 @@ def check_required_keys(config):
|
|||
raise ConfigValidationException("Missing required keys: {}".format(", ".join(missing_keys)))
|
||||
|
||||
|
||||
def test_output(config):
|
||||
abs_output_dir = os.path.abspath(config.output_dir)
|
||||
if not os.path.isdir(abs_output_dir):
|
||||
raise ConfigValidationException("Can't find output directory '{}'".format(abs_output_dir))
|
||||
if not config.output_formats:
|
||||
raise ConfigValidationException("No output formats specified")
|
||||
invalid_formats = [key for key in config.output_formats if key not in ['html', 'pdf']]
|
||||
if invalid_formats:
|
||||
raise ConfigValidationException("Invalid output formats provided: '{}'".format(", ".join(invalid_formats)))
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
check_required_keys(config)
|
||||
test_output(config)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class PrematureExit(Exception):
|
||||
class BaseException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigValidationException(Exception):
|
||||
class PrematureExit(BaseException):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigValidationException(BaseException):
|
||||
pass
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
input: "*.md"
|
||||
output_formats:
|
||||
- html
|
||||
- pdf
|
||||
output_dir: out/
|
Reference in a new issue