From 5a8f5e16036578cfeab67915b133e163ad6982e0 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sat, 6 Mar 2021 21:34:23 +0100 Subject: [PATCH] Scripts added to create requirement specification document --- __init__.py | 20 -------------------- scripts/Makefile | 14 ++++++++++++++ scripts/parse.py | 36 ++++++++++++++++++++++++++++++++++++ templates/Makefile | 17 ----------------- 4 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 scripts/Makefile create mode 100644 scripts/parse.py delete mode 100644 templates/Makefile diff --git a/__init__.py b/__init__.py index 67afe58..bd5e0da 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,3 @@ -import optparse -import os -import sys - from reqif import xml_parser from reqif import reqif_conv @@ -69,19 +65,3 @@ class reqif(object): def get_title(self): return self._data._title - - -if __name__ == '__main__': - parser = optparse.OptionParser("usage: %%prog reqif_file [options]") - (options, args) = parser.parse_args() - - # - # Check options and args - if len(args) != 1 or not os.path.isfile(args[0]): - parser.print_help() - else: - reqif_path = args[0] - tex_path = os.path.abspath(os.path.splitext(reqif_path)[0] + '.tex') - reqif_data = reqif_dict(reqif_path, 'Heading', 'Software Specification') - reqif_conv.tex_gen(reqif_data, tex_path) - sys.exit(reqif_conv.pdf_gen(tex_path)) diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 0000000..df86940 --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,14 @@ +.PHONY: all +.PRECIOUS: %.tex + +all: specification.pdf clean + +%.tex: %.reqif + python3 reqif/scripts/parse.py $< + +%.pdf: %.tex + latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make $< + +clean: + latexmk -c + rm -f *~ *.tex diff --git a/scripts/parse.py b/scripts/parse.py new file mode 100644 index 0000000..fd5649f --- /dev/null +++ b/scripts/parse.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +import jinja2 +import optparse +import os +import sys + +BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) +sys.path.insert(0, BASEPATH) + +import reqif + + +if __name__ == '__main__': + parser = optparse.OptionParser("usage: %prog reqif_file") + parser.add_option("-t", "--template", dest="template", default=os.path.join(BASEPATH, 'reqif', 'templates', 'tex', 'requirement_specification.tex'), help="path to the template") + (options, args) = parser.parse_args() + + # + # Check options and args + if len(args) != 1 or not os.path.isfile(args[0]): + parser.print_help() + else: + reqif_path = args[0] + template_path = os.path.abspath(options.template) + output_path = os.path.splitext(reqif_path)[0] + os.path.splitext(template_path)[1] + if reqif_path == output_path: + sys.exit('ERROR: Source and Destination would be the same file') + # + reqif_data = reqif.reqif_dict(reqif_path, 'Heading', 'Software Specification') + # + with open(output_path, 'w') as fh: + jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(template_path))) + template = jenv.get_template(os.path.basename(template_path)) + fh.write(template.render(data=reqif_data)) diff --git a/templates/Makefile b/templates/Makefile deleted file mode 100644 index 87c5f1f..0000000 --- a/templates/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -SPEC_FILENAME=requirements - -.PHONY: specification - -specification: - venv/bin/python reqif/__init__.py $(SPEC_FILENAME).reqif - @$(MAKE) --no-print-directory clean - xdg-open $(SPEC_FILENAME).pdf - -clean: - @echo Removing generated files for target - @rm -f $(SPEC_FILENAME).tex $(SPEC_FILENAME).aux $(SPEC_FILENAME).log $(SPEC_FILENAME).out $(SPEC_FILENAME).toc *~ - - -cleanall: clean - @echo Removing target - @rm -f $(SPEC_FILENAME).pdf \ No newline at end of file