From 4e5353069101e9b9d06b17fa37c6a0ee30a1137e Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Tue, 24 Oct 2023 00:59:43 +0530 Subject: [PATCH] feat/scripts: support generating PDFs for platforms (#11195) * feat/scripts: support generating PDFs for platform Signed-off-by: K.B.Dharun Krishna * render.py: reformat code for black Signed-off-by: K.B.Dharun Krishna * PDF/README: update command Signed-off-by: K.B.Dharun Krishna * render.py: update code Signed-off-by: K.B.Dharun Krishna * render.py: drop platform none parameter from main Signed-off-by: K.B.Dharun Krishna --------- Signed-off-by: K.B.Dharun Krishna --- scripts/pdf/README.md | 2 +- scripts/pdf/render.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/pdf/README.md b/scripts/pdf/README.md index 088a3d0df..6caa2cf25 100644 --- a/scripts/pdf/README.md +++ b/scripts/pdf/README.md @@ -19,7 +19,7 @@ Make sure OS specific dependencies for WeasyPrint are installed by following the Generating the PDF is as simple as running: - python3 render.py [--color ] [--output ] + python3 render.py [--color ] [--output ] [--platform ] Complete information about the arguments can be viewed by running: diff --git a/scripts/pdf/render.py b/scripts/pdf/render.py index d431a1b74..3e7285e4d 100644 --- a/scripts/pdf/render.py +++ b/scripts/pdf/render.py @@ -17,7 +17,7 @@ from datetime import datetime from weasyprint import HTML -def main(loc, colorscheme, output_filename): +def main(loc, colorscheme, output_filename, platform): # Checking correctness of path if not os.path.isdir(loc): print("Invalid directory. Please try again!", file=sys.stderr) @@ -43,6 +43,9 @@ def main(loc, colorscheme, output_filename): # Writing names of all directories inside 'pages' to a list for operating_sys in sorted(os.listdir(loc)): + if platform and operating_sys not in platform: + continue + # Required string to create directory title pages html += ( "

" @@ -70,6 +73,9 @@ def main(loc, colorscheme, output_filename): html += "" # Writing the PDF to disk + if platform: + output_filename = f"{output_filename[:-4]}-{'+'.join(platform)}.pdf" + print("\nConverting all pages to PDF...") HTML(string=html).write_pdf(output_filename, stylesheets=csslist) @@ -97,6 +103,12 @@ if __name__ == "__main__": default="tldr-book.pdf", help="Custom filename for the output PDF (default is 'tldr-book.pdf')", ) + parser.add_argument( + "-p", + "--platform", + nargs="+", + help="Specify one or more platforms to generate PDFs for", + ) args = parser.parse_args() - main(args.dir_path, args.color, args.output) + main(args.dir_path, args.color, args.output, args.platform)