diff --git a/chatops/bash/handler_build b/chatops/bash/handler_build index cd1177c..f381527 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 @@ -100,14 +101,17 @@ 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 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 + $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 @@ -115,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 @@ -130,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 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) diff --git a/xml/Makefile b/xml/Makefile index 321b5c3..caa9766 100644 --- a/xml/Makefile +++ b/xml/Makefile @@ -8,6 +8,7 @@ MV = mv -f RM = rm -f UNZIP = unzip WGET = wget +XSLTPROC= xsltproc --nonet --xinclude all: $(TARGETS) @@ -35,4 +36,10 @@ clean: distclean: clean $(RM) -- $(TARGETS) -.PHONY: clean distclean +export-csv: sample-report/source/report.xml + @$(XSLTPROC) "xslt/findings2csv.xsl" "sample-report/source/report.xml" + +export-json: sample-report/source/report.xml + @$(XSLTPROC) "xslt/findings2json.xsl" "sample-report/source/report.xml" + +.PHONY: clean distclean export-csv export-json diff --git a/xml/xslt/findings2json.xsl b/xml/xslt/findings2json.xsl new file mode 100644 index 0000000..c1fd2a3 --- /dev/null +++ b/xml/xslt/findings2json.xsl @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + " + \" + + + \n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "projects": [ + "key": "<KEY>", + "issues": [ + ] + ] +} + + + + { + "status": "To Do", + "reporter": "ROS", + "externalId": "", + "issueType": "", + "priority": "", + "summary": "", + "description": "\n\n\nTechnical description:\n\n\n\n\nImpact:\n\n\n\n\nRecommendation:\n\n * \n" + }, + +