Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jamesbr3 split pdf #6

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/r3threatmodeling/fullBuildSinglePDF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import argparse
import os
import importlib_resources
import shutil
import yaml
import re

def generatePDF(rootTMYaml, outputDir, outputName = None):

print("Generating PDF from html version")

tm = yaml.safe_load(rootTMYaml)
tmID = tm['ID']

if not outputName:
title = tm['title']
version = tm['version']
outputName = f'{title} Threat Model-{version}'
outputName = re.sub('[^\w_.)(_-]', '_', outputName) # replace invalid chars with underscore

os.makedirs( "build/scripts", exist_ok=True)
PDFscript = importlib_resources.files('r3threatmodeling').joinpath('scripts/pdfScript.js')
shutil.copy(PDFscript, 'build/scripts/pdfScript.js')


PDF_command =f"docker run -it --init --cap-add=SYS_ADMIN -v {os.path.realpath('build/scripts')}:/home/pptruser/scripts -v \
{os.path.realpath(outputDir)}/:/home/pptruser/{outputDir} --rm ghcr.io/puppeteer/puppeteer:latest node scripts/pdfScript.js \
file:///home/pptruser/{outputDir}/{tmID}.html {outputDir}/{outputName}.pdf"
print(f"Executing command: {PDF_command}")
os.system(PDF_command)

def main():
CLI=argparse.ArgumentParser()

CLI.add_argument(
"--rootTMYaml",
default = None,
required=True,
type=open
)

CLI.add_argument(
"--outputDir",
default = "build",
required=False
)

CLI.add_argument(
"--outputName",
default = None,
required=False
)


args = CLI.parse_args()
generatePDF(args.rootTMYaml, args.outputDir, args.outputName)



if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion src/r3threatmodeling/fullBuildSingleTM.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def generateSingleTM(rootTMYaml, outputDir, assetDir, template, ancestorData=Tru
print(f" executing: {PUMLCommand}")
os.system(PUMLCommand)

"""
print("Generating PDF from html version")

os.makedirs( "build/scripts", exist_ok=True)
Expand All @@ -75,7 +76,8 @@ def generateSingleTM(rootTMYaml, outputDir, assetDir, template, ancestorData=Tru
file:///home/pptruser/{outputDir}/{tmID}.html {outputDir}/{tmID}.pdf"
print(f"Executing command: {PDF_command}")
os.system(PDF_command)

"""

def main():
CLI=argparse.ArgumentParser()

Expand Down