#!/usr/bin/env python
# Compile all the markdown files to LaTeX.
# Requires Pandoc and LaTeX installed
# Also probably only works on Unix. Windows is terrible anyways.

import subprocess
import os

OUT_FOLDER = 'out'
OUT_MD = 'out.md'
OUT_PDF = 'Pheme.pdf'

INCLUDE = ['Title',
           'Abstract',
           'Introduction',
           'Use/Use',
           'Use/Interface',
           'Integrate/Integrate',
           'Integrate/Java/Getting-Started-Java',
           'Integrate/Java/Using-Java-API',
           'Develop/Develop',
           'Develop/Requirements',
           'Develop/Terminology',
           'Develop/Architecture',
           'Develop/Extending',
           'Develop/Performance-Test',
           'Future-Work-Conclusions',
           'References']

md_path = os.path.join(OUT_FOLDER, OUT_MD)
pdf_path = os.path.join(OUT_FOLDER, OUT_PDF)

text = ''
# Get all the datas.
for x in INCLUDE:
    with open('%s.md' % x) as f:
        text += f.read() + '\n\n'

# Wri-wri-write it out.
if not os.path.exists(OUT_FOLDER):
    os.makedirs(OUT_FOLDER)

with open(md_path, 'w') as f:
    f.write(text)

# Shake them dreads.
subprocess.call(['pandoc', md_path, '--variable', 'mainfont=Georgia',
                 '--variable', 'fontsize=12pt', '--toc', '--toc-depth=4',
                 '-o', pdf_path])