From 964d5238d0176bb0bf6e2a2628e935da73cffc81 Mon Sep 17 00:00:00 2001 From: skyanth Date: Fri, 28 Jun 2019 14:48:50 +0200 Subject: [PATCH 1/4] simplified handling of multiple .fo files --- chatops/python/docbuilder.py | 51 ++++++++++-------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/chatops/python/docbuilder.py b/chatops/python/docbuilder.py index 09c5dc0..73299c8 100644 --- a/chatops/python/docbuilder.py +++ b/chatops/python/docbuilder.py @@ -233,43 +233,20 @@ def main(): format(options['output'], exception.strerror), result) result = to_fo(options) if result: - if OFFERTE in options['xslt']: # an offerte can generate multiple fo's - report_output = options['output'] - verboseprint('generating separate waivers detected') - output_dir = os.path.dirname(options['output']) - fop_dir = os.path.dirname(options['fop']) - try: - for fop in [os.path.splitext(x)[0] for x in - os.listdir(fop_dir) if x.endswith('fo')]: - if WAIVER in fop: - options['output'] = output_dir + os.sep + fop + '.pdf' - else: - options['output'] = report_output - options['fop'] = fop_dir + os.sep + fop + '.fo' - result = to_pdf(options) and result - except OSError as exception: - print_exit('[-] ERR: {0}'.format(exception.strerror), - exception.errno) - 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']) - fop_dir = os.path.dirname(options['fop']) - try: - for fop in [os.path.splitext(x)[0] for x in - os.listdir(fop_dir) if x.endswith('fo')]: - if EXECSUMMARY in fop: - options['output'] = output_dir + os.sep + fop + '.pdf' - else: - options['output'] = report_output - options['fop'] = fop_dir + os.sep + fop + '.fo' - result = to_pdf(options) and result - except OSError as exception: - print_exit('[-] ERR: {0}'.format(exception.strerror), - exception.errno) - else: - result = to_pdf(options) - + output_dir = os.path.dirname(options['output']) + fop_dir = os.path.dirname(options['fop']) + remaining_fo = [os.path.splitext(x)[0] for x in os.listdir(fop_dir) if x.endswith('fo') and not 'offerte' in x and not 'report' in x] + result = to_pdf(options) + if len(remaining_fo) > 0: + print('[+] Generating additional .fo files...') + try: + for fo in remaining_fo: + options['output'] = output_dir + os.sep + fo + '.pdf' + options['fop'] = fop_dir + os.sep + fo + '.fo' + result = to_pdf(options) and result + except OSError as exception: + print_exit('[-] ERR: {0}'.format(exception.strerror), + exception.errno) else: print_exit('[-] Unsuccessful (error {0})'.format(result), result) sys.exit(not result) From b4f61f355d319cc76eac3f18b76fd346f122e0a6 Mon Sep 17 00:00:00 2001 From: skyanth Date: Fri, 28 Jun 2019 14:59:52 +0200 Subject: [PATCH 2/4] passes proper fo name; generates html and md --- chatops/bash/handler_build | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/chatops/bash/handler_build b/chatops/bash/handler_build index cd1177c..1d38fbb 100755 --- a/chatops/bash/handler_build +++ b/chatops/bash/handler_build @@ -16,7 +16,7 @@ # (at your option) any later version. -VERSION=0.11 +VERSION=0.12 DOCBUILDER=/usr/local/bin/docbuilder.py TEMPLOC=$(mktemp -d) @@ -33,24 +33,25 @@ BRANCH=master # Set the default PDF name based on the target name TARGETPDF="target/$TARGET-latest.pdf" +# Read optional arguments # Reading positional parms is a bit ugly, shifting parms or getopt would be nicer if [[ ! -z $3 ]]; then if [[ ! $3 == -* ]]; then NAMESPACE=$3 else - PARMS=$3 + PARAMS=$3 fi fi if [[ ! -z $4 ]]; then if [[ ! $3 == -* ]]; then BRANCH=$4 else - PARMS="$PARMS $4" + PARAMS="$PARAMS $4" fi fi if [[ $# -ge 5 ]]; then shift 4 - PARMS="$PARMS $@" + PARAMS="$PARAMS $@" fi trap cleanup EXIT QUIT From 2541f83c2990aea6157fa376eb85bed60a55af98 Mon Sep 17 00:00:00 2001 From: skyanth Date: Fri, 28 Jun 2019 15:00:20 +0200 Subject: [PATCH 3/4] passes proper fo; generates html and md --- chatops/bash/handler_build | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/chatops/bash/handler_build b/chatops/bash/handler_build index 1d38fbb..887de73 100755 --- a/chatops/bash/handler_build +++ b/chatops/bash/handler_build @@ -105,10 +105,13 @@ build() { TARGETPDF="target/quote_${REPO/off-/}.pdf" elif [[ $TARGET == "report" ]]; then TARGETPDF="target/report_${REPO/pen-/}.pdf" + TARGETHTML="target/report_${REPO/pen-/}.html" + TARGETMD="target/report_${REPO/pen-/}.md" fi - $DOCBUILDER -c -i $TARGET.xml -o ../$TARGETPDF -x ../xslt/generate_$TARGET.xsl $PARMS + TARGETFO="target/${TARGET}.fo" + $DOCBUILDER -c -i $TARGET.xml -f $TARGETFO -o ../$TARGETPDF -x ../xslt/generate_$TARGET.xsl $PARAMS $NOPRINT if [[ $? -ne 0 ]]; then - echo "[-] Sorry, failed to parse $TARGET. Use \`builder $TARGET $REPO $NAMESPACE $BRANCH -v\` for more information." + echo "[-] Sorry, failed to parse $TARGET. Use \`build $TARGET $REPO $NAMESPACE $BRANCH -v\` for more information." exit 1 fi popd &>/dev/null @@ -116,10 +119,23 @@ build() { echo "[-] hmmm... failed to build PDF file (could not find $TARGETPDF)" exit 1 fi + if [ $TARGET == "report" ]; then + java -jar /usr/local/bin/saxon/saxon9he.jar -s:source/$TARGET.xml -o:$TARGETHTML -xsl:xslt/generate_html_$TARGET.xsl -xi + if [ ! -f $TARGETHTML ]; then + echo "[-] Note: failed to build HTML file (could not find $TARGETHTML)" + else + pandoc $TARGETHTML -t markdown_strict -o $TARGETMD + if [ ! -f $TARGETMD ]; then + echo "[-] Note: failed to build markdown file (could not find $TARGETMD)" + fi + fi + fi } add_to_repo() { git add $TARGETPDF + git add $TARGETHTML &>/dev/null + git add $TARGETMD &>/dev/null git add target/waiver_?*.pdf &>/dev/null git add target/execsummary.pdf &>/dev/null git commit -q -m "$TARGETPDF proudly manufactured using ChatOps" &>/dev/null @@ -131,5 +147,14 @@ echo "builder v$VERSION - Rocking your world, one build at a time..." clone_repo build add_to_repo -echo "[+] listo! Check out $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$TARGETPDF" +echo " [+] Get PDF: $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$TARGETPDF" +if [[ -f target/execsummary.pdf ]]; then + echo " [+] Get exec summary PDF: $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/target/execsummary.pdf" +fi +if [[ $TARGET == "report" && -f $TARGETHTML ]]; then + echo " [+] Download HTML: $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$TARGETHTML" +fi +if [[ $TARGET == "report" && -f $TARGETMD ]]; then + echo " [+] Quick look (rendered MarkDown): $GITWEB/$NAMESPACE/$REPO/blob/$BRANCH/$TARGETMD" +fi exit 0 From 27cfc30de46087108c5702cc39240c93cc5f9fac Mon Sep 17 00:00:00 2001 From: skyanth Date: Mon, 1 Jul 2019 09:12:19 +0200 Subject: [PATCH 4/4] typo --- chatops/bash/handler_build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatops/bash/handler_build b/chatops/bash/handler_build index 887de73..f381527 100755 --- a/chatops/bash/handler_build +++ b/chatops/bash/handler_build @@ -101,6 +101,7 @@ build() { fi pushd source &>/dev/null backwards_compatible + TARGETFO="target/${TARGET}.fo" if ([[ $TARGET == "quote" ]] || [[ $TARGET == "offerte" ]]); then TARGETPDF="target/quote_${REPO/off-/}.pdf" elif [[ $TARGET == "report" ]]; then @@ -108,8 +109,7 @@ build() { TARGETHTML="target/report_${REPO/pen-/}.html" TARGETMD="target/report_${REPO/pen-/}.md" fi - TARGETFO="target/${TARGET}.fo" - $DOCBUILDER -c -i $TARGET.xml -f $TARGETFO -o ../$TARGETPDF -x ../xslt/generate_$TARGET.xsl $PARAMS $NOPRINT + $DOCBUILDER -c -i $TARGET.xml -f ../$TARGETFO -o ../$TARGETPDF -x ../xslt/generate_$TARGET.xsl $PARAMS $NOPRINT if [[ $? -ne 0 ]]; then echo "[-] Sorry, failed to parse $TARGET. Use \`build $TARGET $REPO $NAMESPACE $BRANCH -v\` for more information." exit 1