Remove the damn dotmap
This commit is contained in:
parent
339c4a3df2
commit
2e08bdf798
6 changed files with 23 additions and 28 deletions
|
@ -6,10 +6,10 @@ import os
|
|||
|
||||
|
||||
def build(config):
|
||||
data = read_files(os.path.abspath(config.input))
|
||||
doc = build_document(data, getattr(config, 'bibliography', None), getattr(config, 'context', None))
|
||||
if 'html' in config.output_formats:
|
||||
output_html(doc, os.path.abspath(config.output_dir))
|
||||
if 'pdf' in config.output_formats:
|
||||
render_cover(config.context.toDict())
|
||||
data = read_files(os.path.abspath(config['input']))
|
||||
doc = build_document(data, config.get('bibliography'), config.get('context'))
|
||||
if 'html' in config['output_formats']:
|
||||
output_html(doc, os.path.abspath(config['output_dir']))
|
||||
if 'pdf' in config['output_formats']:
|
||||
render_cover(config['context'])
|
||||
export_pdf(doc, config)
|
||||
|
|
|
@ -35,8 +35,8 @@ def build_document(files_content, bibliography, context):
|
|||
filters = []
|
||||
if bibliography is not None:
|
||||
args += [
|
||||
'--bibliography={}'.format(os.path.abspath(bibliography.references)),
|
||||
'--csl={}'.format(os.path.join(CSL_DIR, "{}.csl".format(bibliography.csl)))
|
||||
'--bibliography={}'.format(os.path.abspath(bibliography['references'])),
|
||||
'--csl={}'.format(os.path.join(CSL_DIR, "{}.csl".format(bibliography['csl'])))
|
||||
]
|
||||
filters.append('pandoc-citeproc')
|
||||
|
||||
|
@ -48,4 +48,4 @@ def build_document(files_content, bibliography, context):
|
|||
filters=filters
|
||||
))
|
||||
|
||||
return parse_template(html, context.toDict())
|
||||
return parse_template(html, context)
|
||||
|
|
|
@ -24,12 +24,12 @@ PDF_OPTIONS = {
|
|||
|
||||
|
||||
def export_pdf(content, config):
|
||||
PDF_OPTIONS['title'] = getattr(config, 'title', 'output')
|
||||
PDF_OPTIONS['replace'] = list(config.context.items())
|
||||
PDF_OPTIONS['title'] = config.get('title', 'Output')
|
||||
PDF_OPTIONS['replace'] = list(config['context'].items())
|
||||
|
||||
return pdfkit.from_string(
|
||||
content,
|
||||
os.path.join(os.path.abspath(config.output_dir), 'output.pdf'),
|
||||
os.path.join(os.path.abspath(config['output_dir']), 'output.pdf'),
|
||||
options=PDF_OPTIONS,
|
||||
css=STYLE_FILE,
|
||||
cover=OUTPUT_COVER_FILE
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import yaml
|
||||
from dotmap import DotMap
|
||||
import os
|
||||
from md_pdf.consts import CONFIG_FILE
|
||||
from md_pdf.exceptions import ConfigValidationException
|
||||
|
@ -8,6 +7,6 @@ from md_pdf.exceptions import ConfigValidationException
|
|||
def load_config():
|
||||
try:
|
||||
with open(os.path.join(CONFIG_FILE)) as f:
|
||||
return DotMap(yaml.load(f))
|
||||
return yaml.load(f)
|
||||
except FileNotFoundError:
|
||||
raise ConfigValidationException("Can't find config file at {}".format(CONFIG_FILE))
|
||||
|
|
|
@ -2,7 +2,6 @@ from md_pdf.exceptions import ConfigValidationException
|
|||
from md_pdf.consts import CSL_DIR
|
||||
import glob
|
||||
import os
|
||||
from dotmap import DotMap
|
||||
|
||||
|
||||
REQUIRED_KEYS = [
|
||||
|
@ -19,18 +18,16 @@ def check_required_keys(config):
|
|||
|
||||
|
||||
def test_output(config):
|
||||
abs_output_dir = os.path.abspath(config.output_dir)
|
||||
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']]
|
||||
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 test_input(config):
|
||||
abs_input = os.path.abspath(config.input)
|
||||
abs_input = os.path.abspath(config['input'])
|
||||
if len(glob.glob(abs_input)) == 0:
|
||||
raise ConfigValidationException("No files found at {}".format(abs_input))
|
||||
|
||||
|
@ -38,14 +35,14 @@ def test_input(config):
|
|||
def validate_bibliography(config):
|
||||
if 'bibliography' not in config:
|
||||
return
|
||||
if 'references' not in config.bibliography:
|
||||
if 'references' not in config['bibliography']:
|
||||
raise ConfigValidationException("Missing References Path")
|
||||
|
||||
abs_bibliography = os.path.abspath(config.bibliography.references)
|
||||
abs_bibliography = os.path.abspath(config['bibliography']['references'])
|
||||
if not os.path.isfile(abs_bibliography):
|
||||
raise ConfigValidationException("Invalid bibliography path: '{}'".format(abs_bibliography))
|
||||
if 'csl' in config.bibliography:
|
||||
if not os.path.isfile(os.path.join(CSL_DIR, "{}.csl".format(config.bibliography.csl))):
|
||||
if 'csl' in config['bibliography']:
|
||||
if not os.path.isfile(os.path.join(CSL_DIR, "{}.csl".format(config['bibliography']['csl']))):
|
||||
raise ConfigValidationException("Could not find CSL '{}'".format(config.bibliography.csl))
|
||||
|
||||
|
||||
|
@ -53,14 +50,14 @@ def validate_context(config):
|
|||
if 'context' not in config:
|
||||
return
|
||||
|
||||
if type(config.context) != DotMap:
|
||||
if type(config['context']) != dict:
|
||||
raise ConfigValidationException("Context must be key:value store")
|
||||
|
||||
non_str_keys = [key for key in config.context.keys() if type(key) != str]
|
||||
non_str_keys = [key for key in config['context'].keys() if type(key) != str]
|
||||
if non_str_keys:
|
||||
raise ConfigValidationException("Context keys must be strings. Non-strings: {}".format(", ".join(non_str_keys)))
|
||||
|
||||
invalid_values = [value for value in config.context.values() if type(value) in [list, dict, DotMap]]
|
||||
invalid_values = [value for value in config['context'].values() if type(value) in [list, dict]]
|
||||
if invalid_values:
|
||||
raise ConfigValidationException("Context keys must be plain. Invalid values: {}".format(", ".join(invalid_values)))
|
||||
|
||||
|
|
1
setup.py
1
setup.py
|
@ -6,7 +6,6 @@ setup(
|
|||
version="1.0",
|
||||
install_requires=[
|
||||
"beautifulsoup4==4.5.3",
|
||||
"dotmap==1.2.17",
|
||||
"jinja2==2.9.5",
|
||||
"pdfkit==0.6.1",
|
||||
"progressbar2==3.16.0",
|
||||
|
|
Reference in a new issue