From 8f30f20d2bf014ea323a7eb30c2a3ba1483c9396 Mon Sep 17 00:00:00 2001 From: Dan McKinley Date: Tue, 5 Nov 2024 12:24:08 -0800 Subject: [PATCH] switching to click for better path handling --- keynote_export/export.py | 103 ++++++++++++++++++++++----------------- poetry.lock | 27 +++++++++- pyproject.toml | 3 +- 3 files changed, 87 insertions(+), 46 deletions(-) diff --git a/keynote_export/export.py b/keynote_export/export.py index f36046c..46834fc 100755 --- a/keynote_export/export.py +++ b/keynote_export/export.py @@ -2,11 +2,12 @@ import itertools import os import shutil -from argparse import ArgumentParser from contextlib import closing from glob import glob +from typing import Optional import appscript +import click from jinja2 import Environment, FileSystemLoader from reportlab.lib.colors import HexColor from reportlab.lib.enums import TA_LEFT @@ -154,54 +155,68 @@ def imgpath(s): ) -def main(): - ap = ArgumentParser() - ap.add_argument( - "-k", "--keynote", help="Path to the keynote to convert", required=True - ) - ap.add_argument( - "-o", "--outdir", help="Where to put the output.", required=True - ) - ap.add_argument( - "-p", "--pagesize", help="The size of the pages.", default="1920x1080" - ) - ap.add_argument( - "-f", - "--font-size", - help="Font size for notes", - type=int, - dest="font_size", - default=36, - ) - ap.add_argument("-t", "--title", help="Title of the presentation") - ap.add_argument( - "-u", - "--bluesky-handle", - help="BlueSky handle for author", - dest="bsky_handle", - ) - ap.add_argument( - "-sb", - "--skip-builds", - help="Skip build stages and just output one JPG per slide", - action="store_true", - dest="skip_builds", - ) - - args = ap.parse_args() - pagesize = tuple([int(s) for s in args.pagesize.split("x")]) +@click.command() +@click.option( + "-k", + "--keynote", + type=click.Path(exists=True, file_okay=True, dir_okay=False), + help="Path to the keynote to convert", + required=True, +) +@click.option( + "-o", + "--outdir", + type=click.Path(file_okay=False, dir_okay=True), + help="Where to put the output.", + required=True, +) +@click.option( + "-p", + "--pagesize", + default="1920x1080", + help="The size of the pages.", + type=click.STRING, +) +@click.option( + "-f", + "--font-size", + type=click.INT, + help="Font size for notes", + default=36, +) +@click.option("-t", "--title", help="Title of the presentation", required=True) +@click.option( + "-u", + "--bluesky-handle", + help="BlueSky handle for author", + required=False, + type=click.STRING, +) +@click.option( + "--skip-builds", is_flag=True, help="Skip build stages", default=False +) +def main( + keynote: str, + outdir: str, + pagesize: str, + font_size: int, + title: str, + bluesky_handle: Optional[str], + skip_builds: bool, +): + pagesize = tuple([int(s) for s in pagesize.split("x")]) opts = Options( - args.outdir, + outdir, pagesize, - args.font_size, - args.title, - args.bsky_handle, - args.skip_builds, + font_size, + title, + bluesky_handle, + skip_builds, ) - print("Processing", args.keynote) + print("Processing", keynote) make_dirs(opts) - notes = export_keynote(args.keynote, opts) + notes = export_keynote(keynote, opts) generate_pdf(opts, notes) generate_html(opts, notes) diff --git a/poetry.lock b/poetry.lock index 4e8bc20..87ebc16 100644 --- a/poetry.lock +++ b/poetry.lock @@ -34,6 +34,31 @@ files = [ {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, ] +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + [[package]] name = "jinja2" version = "3.1.4" @@ -390,4 +415,4 @@ renderpm = ["rl-renderPM (>=4.0.3,<4.1)"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "562c1624ec53504d777564ae73ff5bc76105cbeb769cd576c94dab90d0a625f2" +content-hash = "b6ab623c7df0ab25db8b13a497ebabe7465ef9a4608d8aaffffd470658969f56" diff --git a/pyproject.toml b/pyproject.toml index b46b85b..ae0ac49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keynote_export" -version = "0.1.4" +version = "0.1.5" description = "" authors = ["Dan McKinley "] repository = "https://github.com/mcfunley/better-keynote-export" @@ -35,6 +35,7 @@ python = "^3.12" jinja2 = "^3.1.4" appscript = "^1.3.0" reportlab = "^4.2.5" +click = "^8.1.7" [build-system] requires = ["poetry-core"]