76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
"""
|
|
Create pdf manuals from the markdown files in the cpdctrl-gui resources directory
|
|
"""
|
|
import os, markdown
|
|
import pymupdf
|
|
import datetime
|
|
|
|
from markdown_pdf import MarkdownPdf, Section
|
|
|
|
DOC_DIR = "~/cpd-dev/cpdctrl-gui/cpdctrl_gui/resources"
|
|
OUT_DIR = "~/cpd-dev/docs"
|
|
|
|
def convert(filepath: str):
|
|
with open(filepath, "r") as file:
|
|
content = file.read()
|
|
html = markdown.markdown(content, output_format="html")
|
|
return html
|
|
|
|
def load_md(filename: str):
|
|
with open(os.path.join(DOC_DIR, filename), "r") as file:
|
|
return file.read()
|
|
|
|
metadata = {
|
|
"author": "Matthias Quintern",
|
|
"modDate": datetime.datetime.now().isoformat(),
|
|
}
|
|
|
|
def make_software_manual():
|
|
filepath = os.path.join(OUT_DIR, "cpdctrl-gui-manual.pdf")
|
|
sections = [[
|
|
"# N203 Vacuum CPD Setup: User Manual\n",
|
|
"user_guide.md",
|
|
"sample_changing.md",
|
|
"measurement_settings.md",
|
|
"led_control.md",
|
|
"controller_calibration.md",
|
|
"troubleshooting.md",
|
|
], [
|
|
"# cpdctrl Software Documentation",
|
|
"about.md",
|
|
"technical_information.md",
|
|
]
|
|
]
|
|
|
|
pdf = MarkdownPdf(toc_level=2)
|
|
|
|
for section in sections:
|
|
sec_md = ""
|
|
for entry in section:
|
|
if entry.endswith(".md"):
|
|
entry_md = load_md(entry)
|
|
else:
|
|
entry_md = entry
|
|
sec_md += entry_md + "\n"
|
|
pdf.add_section(Section(sec_md))
|
|
|
|
|
|
for key, val in (metadata | { "title": "cpdctrl-gui-manual"}).items():
|
|
pdf.meta[key] = val
|
|
pdf.save(filepath)
|
|
|
|
|
|
|
|
def recorder(elpos):
|
|
pass
|
|
|
|
if __name__ == '__main__':
|
|
DOC_DIR = os.path.expanduser(DOC_DIR)
|
|
docs = [os.path.join(DOC_DIR, f) for f in os.listdir(DOC_DIR)]
|
|
docs.sort()
|
|
OUT_DIR = os.path.expanduser(OUT_DIR)
|
|
if not os.path.isdir(OUT_DIR):
|
|
os.makedirs(OUT_DIR)
|
|
|
|
make_software_manual()
|