Added styling & introduced pdf passwords

This commit is contained in:
skyanth
2017-08-25 10:08:24 +02:00
parent 45af9e3a1f
commit 68e2a7348d

View File

@@ -23,6 +23,7 @@ from __future__ import print_function
import argparse
import os
import random
import subprocess
from subprocess import PIPE
import sys
@@ -32,7 +33,7 @@ import textwrap
GITREV = 'GITREV' # Magic tag which gets replaced by the git short commit hash
OFFERTE = 'generate_offerte.xsl' # XSL for generating waivers
WAIVER = 'waiver_' # prefix for waivers
EXECSUMMARY = 'execsummary' # generating an executive summary instead of a report
EXECSUMMARY = 'execsummary' # generating an executive summary instead of a report
def parse_arguments():
@@ -56,9 +57,12 @@ the Free Software Foundation, either version 3 of the License, or
help='overwrite output file if it already exists')
parser.add_argument('-date', action='store',
help='the invoice date')
parser.add_argument('-execsummary', action='store_true',
parser.add_argument('--execsummary', action='store_true',
help="""create an executive summary as well as a report (true/false).
Default: false """)
parser.add_argument('--pw', action='store_true',
help="""password-protect the pdf.
Default: false """)
parser.add_argument('--fop-config', action='store',
default='/etc/docbuilder/fop.xconf',
help="""fop configuration file (default
@@ -106,7 +110,7 @@ the Free Software Foundation, either version 3 of the License, or
else:
verboseprint = lambda *a: None
verboseerror = lambda *a: None
return vars(parser.parse_args())
return vars(args)
def print_output(stdout, stderr):
@@ -138,6 +142,13 @@ def change_tag(fop):
print('[-] could not execute git - is git installed ?')
def generate_pw():
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
length = 12
p = "".join(random.sample(s, length))
return(p)
def to_fo(options):
"""
Creates a fo output file based on a XML file.
@@ -171,6 +182,9 @@ def to_pdf(options):
"""
cmd = [options['fop_binary'], '-c', options['fop_config'], options['fop'],
options['output']]
if options['pw']:
pw = generate_pw()
cmd = cmd + ['-u', pw]
try:
verboseprint('Converting {0} to {1}'.format(options['fop'],
options['output']))
@@ -180,6 +194,8 @@ def to_pdf(options):
print_output(stdout, stderr)
if result == 0:
print('[+] Succesfully built ' + options['output'])
if options['pw']:
print('\n[+] Password for this pdf is ' + pw)
except OSError as exception:
print_exit('[-] ERR: {0}'.format(exception.strerror), exception.errno)
return result == 0
@@ -234,7 +250,7 @@ def main():
except OSError as exception:
print_exit('[-] ERR: {0}'.format(exception.strerror),
exception.errno)
if options['execsummary'] == True: # we're generating a summary as well as a report
if options['execsummary']: # we're generating a summary as well as a report
report_output = options['output']
verboseprint('generating additional executive summary')
output_dir = os.path.dirname(options['output'])
@@ -260,4 +276,4 @@ def main():
if __name__ == "__main__":
main()
main()