Przeglądaj źródła

Scripts added to create requirement specification document

master
Dirk Alders 3 lat temu
rodzic
commit
5a8f5e1603
4 zmienionych plików z 50 dodań i 37 usunięć
  1. 0
    20
      __init__.py
  2. 14
    0
      scripts/Makefile
  3. 36
    0
      scripts/parse.py
  4. 0
    17
      templates/Makefile

+ 0
- 20
__init__.py Wyświetl plik

@@ -1,7 +1,3 @@
1
-import optparse
2
-import os
3
-import sys
4
-
5 1
 from reqif import xml_parser
6 2
 from reqif import reqif_conv
7 3
 
@@ -69,19 +65,3 @@ class reqif(object):
69 65
 
70 66
     def get_title(self):
71 67
         return self._data._title
72
-
73
-
74
-if __name__ == '__main__':
75
-    parser = optparse.OptionParser("usage: %%prog reqif_file [options]")
76
-    (options, args) = parser.parse_args()
77
-
78
-    #
79
-    # Check options and args
80
-    if len(args) != 1 or not os.path.isfile(args[0]):
81
-        parser.print_help()
82
-    else:
83
-        reqif_path = args[0]
84
-        tex_path = os.path.abspath(os.path.splitext(reqif_path)[0] + '.tex')
85
-        reqif_data = reqif_dict(reqif_path, 'Heading', 'Software Specification')
86
-        reqif_conv.tex_gen(reqif_data, tex_path)
87
-        sys.exit(reqif_conv.pdf_gen(tex_path))

+ 14
- 0
scripts/Makefile Wyświetl plik

@@ -0,0 +1,14 @@
1
+.PHONY: all
2
+.PRECIOUS: %.tex
3
+
4
+all: specification.pdf clean
5
+
6
+%.tex: %.reqif
7
+	python3 reqif/scripts/parse.py $<
8
+
9
+%.pdf: %.tex
10
+	latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make $<
11
+
12
+clean:
13
+	latexmk -c
14
+	rm -f *~ *.tex

+ 36
- 0
scripts/parse.py Wyświetl plik

@@ -0,0 +1,36 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+import jinja2
5
+import optparse
6
+import os
7
+import sys
8
+
9
+BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
10
+sys.path.insert(0, BASEPATH)
11
+
12
+import reqif
13
+
14
+
15
+if __name__ == '__main__':
16
+    parser = optparse.OptionParser("usage: %prog reqif_file")
17
+    parser.add_option("-t", "--template", dest="template", default=os.path.join(BASEPATH, 'reqif', 'templates', 'tex', 'requirement_specification.tex'), help="path to the template")
18
+    (options, args) = parser.parse_args()
19
+
20
+    #
21
+    # Check options and args
22
+    if len(args) != 1 or not os.path.isfile(args[0]):
23
+        parser.print_help()
24
+    else:
25
+        reqif_path = args[0]
26
+        template_path = os.path.abspath(options.template)
27
+        output_path = os.path.splitext(reqif_path)[0] + os.path.splitext(template_path)[1]
28
+        if reqif_path == output_path:
29
+            sys.exit('ERROR: Source and Destination would be the same file')
30
+        #
31
+        reqif_data = reqif.reqif_dict(reqif_path, 'Heading', 'Software Specification')
32
+        #
33
+        with open(output_path, 'w') as fh:
34
+            jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(template_path)))
35
+            template = jenv.get_template(os.path.basename(template_path))
36
+            fh.write(template.render(data=reqif_data))

+ 0
- 17
templates/Makefile Wyświetl plik

@@ -1,17 +0,0 @@
1
-SPEC_FILENAME=requirements
2
-
3
-.PHONY: specification
4
-
5
-specification:
6
-	venv/bin/python reqif/__init__.py $(SPEC_FILENAME).reqif
7
-	@$(MAKE) --no-print-directory clean
8
-	xdg-open $(SPEC_FILENAME).pdf
9
-
10
-clean:
11
-	@echo Removing generated files for target
12
-	@rm -f $(SPEC_FILENAME).tex $(SPEC_FILENAME).aux $(SPEC_FILENAME).log $(SPEC_FILENAME).out $(SPEC_FILENAME).toc *~
13
-
14
-
15
-cleanall: clean
16
-	@echo Removing target
17
-	@rm -f $(SPEC_FILENAME).pdf

Ładowanie…
Anuluj
Zapisz