Skip to content

Commit

Permalink
doc2pdf: add optional outdir
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Dec 12, 2023
1 parent caf47b9 commit 5d21716
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/loutils/doc2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from . import docfinder, get_lo_exe


def doc2pdf(filein: Path):
cmd = [get_lo_exe(), "--convert-to", "pdf", "--outdir", str(filein.parent), str(filein)]
def doc2pdf(filein: Path, out_dir: Path | None = None):

if not out_dir:
out_dir = filein.parent

cmd = [get_lo_exe(), "--convert-to", "pdf", "--outdir", str(out_dir), str(filein)]

subprocess.check_call(cmd)

Expand All @@ -24,8 +28,12 @@ def doc2pdf(filein: Path):
p = argparse.ArgumentParser()
p.add_argument("path", help="path to work in")
p.add_argument("-s", "--suffix", help="file extensions to convert", nargs="+")
p.add_argument("-o", "--outdir", help="output directory")
P = p.parse_args()

if P.outdir:
outdir = Path(P.outdir).expanduser().resolve()

for f in docfinder(P.path, P.suffix, exclude=".pdf"):
print(f"converting to PDF: {f}")
doc2pdf(f)
doc2pdf(f, outdir)

0 comments on commit 5d21716

Please sign in to comment.