Commit 3237ec9c authored by rhpvorderman's avatar rhpvorderman

Before creating new documents with the script

parent 2299e7a9
#!/bin/bash
#Script to document not yet documented tools in biopet
#Declare variables
BIOPET_DIR=~/biopet
TOOLS_DIR=$BIOPET_DIR/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools
DOCS_DIR=$BIOPET_DIR/docs/tools
TEMPLATE=$BIOPET_DIR/biopet-autodoc/tools_doc_template.j2
BIOPET="java -jar $BIOPET_JAR tool" #Make sure the BIOPET_JAR environment variable is defined!
for file in $TOOLS_DIR/*.scala #For loop checking all scala files in the tools section
do
file_no_path=${file##*/}
file_no_extension=${file_no_path%.scala}
file_with_md=${file_no_extension}.md
destfile=$DOCS_DIR/$file_with_md
if [ ! -f $destfile ] #Checks if (tool_name).md is already present. Existing files are skipped
then
eval "$BIOPET $file_no_extension -h 2> help.txt"
if grep -Fxq "ERROR: command '$file_no_extension' does not exist in module 'tool'" help.txt
then
echo "The tool $file_no_extension does not exist in the latest compiled version of biopet"
else
./templateparser.py -t "$TEMPLATE" -o "destfile" -N "$file_no_extension" -L "help.txt"
echo "$destfile created"
fi
rm help.txt
fi
done
#! /usr/bin/env python2
#Script to document new tools using a jinja2 template
from jinja2 import Environment, FileSystemLoader
import os
import argparse
import ast
import yaml
if __name__ == "__main__":
#Block with command line options
parser=argparse.ArgumentParser(description="")
parser.add_argument("-t", type=str, nargs=1, help="Templatefile to be used")
parser.add_argument("-o", type=str, nargs=1, help="output file")
parser.add_argument("-N","--tool-name", type=str, nargs=1, help="name of the tool")
parser.add_argument("-O", "--tool-output", type=str, nargs='?', default='')
parser.add_argument("-R", "--tool-run", type=str, nargs='?', default='')
parser.add_argument("-L", "--tool-option-list", type=str, nargs='?', default= '', help="Text file containing the --help output of the tool")
#parse arguments
arguments=parser.parse_args()
template=arguments.t[0]
output_file=arguments.o[0]
tool=dict()
tool['name']=arguments.tool_name[0]
tool['output']=arguments.tool_output
tool['run']=arguments.tool_run
help_file=open(arguments.tool_option_list, 'r')
tool['option_list']=help_file.read() #This reads the option list file to a raw string
# Open jinja2 template and render it with variables
j2_env = Environment(loader=FileSystemLoader("/"))
rendered = j2_env.get_template(template).render(tool=tool)
# Write the template results to the output file
file=open(output_file, "w")
file.seek(0)
file.write(rendered)
file.close()
# {{tool.name}}
## Introduction
{{tool.introduction|default('')}}
## Example
The help menu:
~~~
{{tool.option_list|default('')}}
~~~
To run the tool use:
~~~
biopet tool {{tool.name}} {{tool.run|default('')}}
~~~
## Output
{{tool.output|default('')}}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment