From 1a090224ad4664f22524b0a91d188f2664cacfb3 Mon Sep 17 00:00:00 2001 From: CPD <CPD@TUZEWSI-2LN203M.ads.mwn.de> Date: Thu, 3 Apr 2025 19:02:48 +0200 Subject: [PATCH] Add scripts --- .scripts/convert_docs_for_website.py | 31 ++++++++++++ .scripts/cpdctrl_gui_launcher.py | 9 ++++ .scripts/install_gui.ps1 | 16 ++++++ .scripts/make_manuals.py | 75 ++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 .scripts/convert_docs_for_website.py create mode 100644 .scripts/cpdctrl_gui_launcher.py create mode 100644 .scripts/install_gui.ps1 create mode 100644 .scripts/make_manuals.py diff --git a/.scripts/convert_docs_for_website.py b/.scripts/convert_docs_for_website.py new file mode 100644 index 0000000..9d6a2d2 --- /dev/null +++ b/.scripts/convert_docs_for_website.py @@ -0,0 +1,31 @@ +""" +Convert the docs to html, so that they can be copy-pasted into the BayernCollab Wiki +""" + +import os, markdown + +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 + +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) + + for file in docs: + if file.endswith(".md"): + html_file = os.path.join(OUT_DIR, os.path.basename(file).replace(".md", ".html")) + print(f"{file} -> {html_file}") + html = convert(file) + html = html.replace("<br>", "<br />") + with open(html_file, "w") as file: + file.write(html) diff --git a/.scripts/cpdctrl_gui_launcher.py b/.scripts/cpdctrl_gui_launcher.py new file mode 100644 index 0000000..003ee50 --- /dev/null +++ b/.scripts/cpdctrl_gui_launcher.py @@ -0,0 +1,9 @@ +# import and run cpdctrl_gui +# when packaging this with pyinstaller, +# cpdctrl_gui will be imported as python package and thus +# have the package metadata (including version number) available +from cpdctrl_gui import init + +if __name__ == '__main__': + import sys + sys.exit(init.run()) diff --git a/.scripts/install_gui.ps1 b/.scripts/install_gui.ps1 new file mode 100644 index 0000000..0e052ad --- /dev/null +++ b/.scripts/install_gui.ps1 @@ -0,0 +1,16 @@ +# This creates & installs cpdctrl-gui using pyinstaller +# into a single, gigantic exe file. Very modern. +# The --paths ..\cpdctrl is necessary, otherwise it takes the version that was installed with pip +cd ~\cpd-dev +.\venv\Scripts\activate.ps1 +mkdir build +cd build +pyinstaller ..\cpdctrl_gui_launcher.py ` + --onefile ` + --name "cpdctrl-gui" ` + --windowed ` + --icon ..\cpdctrl-gui\cpdctrl_gui\resources\icons\icon.png ` + --exclude-module pyside6 ` + --paths ..\cpdctrl ` + --paths ..\cpdctrl_gui ` + --add-data ..\cpdctrl-gui\cpdctrl_gui\resources:cpdctrl_gui\resources \ No newline at end of file diff --git a/.scripts/make_manuals.py b/.scripts/make_manuals.py new file mode 100644 index 0000000..f7121c1 --- /dev/null +++ b/.scripts/make_manuals.py @@ -0,0 +1,75 @@ +""" +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()