Procházet zdrojové kódy

REQIF->TEX->PDF implemented

master
Dirk Alders před 3 roky
rodič
revize
368b42c1ae

+ 21
- 2
__init__.py Zobrazit soubor

@@ -1,5 +1,8 @@
1
+import optparse
1 2
 import os
2
-from reqif import xml_parser
3
+
4
+import xml_parser
5
+import reqif_conv
3 6
 
4 7
 
5 8
 class reqif_dict(dict):
@@ -17,7 +20,7 @@ class reqif_dict(dict):
17 20
         for specification in self.rd.get_specifications():
18 21
             if specification.get(specification_key) == specification_identifier:
19 22
                 sw_spec = specification
20
-                break 
23
+                break
21 24
         #
22 25
         self[self.KEY_ITEM_DICT] = {}
23 26
         for obj_id in sw_spec.children:
@@ -65,3 +68,19 @@ class reqif(object):
65 68
 
66 69
     def get_title(self):
67 70
         return self._data._title
71
+
72
+
73
+if __name__ == '__main__':
74
+    parser = optparse.OptionParser("usage: %%prog reqif_file [options]")
75
+    (options, args) = parser.parse_args()
76
+
77
+    #
78
+    # Check options and args
79
+    if len(args) != 1 or not os.path.isfile(args[0]):
80
+        parser.print_help()
81
+    else:
82
+        reqif_path = args[0]
83
+        tex_path = os.path.abspath(os.path.splitext(reqif_path)[0] + '.tex')
84
+        reqif_data = reqif_dict(reqif_path, 'Heading', 'Software Specification')
85
+        reqif_conv.tex_gen(reqif_data, tex_path)
86
+        reqif_conv.pdf_gen(tex_path)

+ 35
- 0
reqif_conv.py Zobrazit soubor

@@ -0,0 +1,35 @@
1
+#!/usr/bin/env python
2
+
3
+import jinja2
4
+import os
5
+import sys
6
+
7
+
8
+"""fn_tex = 'requirements_specification.tex'
9
+fn_pdf = 'requirements_specification.pdf'
10
+tmp_path = 'tmp'"""
11
+
12
+
13
+def tex_gen(reqif_data, tex_path):
14
+    print('Creating LaTeX-File %s' % tex_path)
15
+    with open(tex_path, 'w') as fh:
16
+        #
17
+        template_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates', 'tex'))
18
+        template_filename = 'requirement_specification.tex'
19
+        jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
20
+        template = jenv.get_template(template_filename)
21
+        fh.write(template.render(data=reqif_data))
22
+
23
+
24
+def pdf_gen(tex_path):
25
+    pdf_path = os.path.splitext(tex_path)[0] + '.pdf'
26
+    print('Creating PDF %s' % pdf_path)
27
+    for i in range(3):
28
+        sys.stdout.write('      Starting run %d/3 of pdflatex... ' % (i + 1))
29
+        sys.stdout.flush()
30
+        exit_value = os.system("pdflatex -interaction nonstopmode %s 1> /dev/null" % tex_path)
31
+        if exit_value != 0:
32
+            print('FAILED')
33
+            break
34
+        else:
35
+            print('SUCCESS')

+ 17
- 0
templates/Makefile Zobrazit soubor

@@ -0,0 +1,17 @@
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

+ 1
- 0
templates/tex/foot.tex Zobrazit soubor

@@ -0,0 +1 @@
1
+\end{document}

+ 96
- 0
templates/tex/head.tex Zobrazit soubor

@@ -0,0 +1,96 @@
1
+{%- import 'macros.tex' as macros %}
2
+\documentclass[a4paper]{article}
3
+%\documentclass[a4paper,landscape]{article}
4
+
5
+\renewcommand{\familydefault}{\sfdefault}
6
+\usepackage[table]{xcolor}
7
+\definecolor{orange}{rgb}{1, 0.7, 0}
8
+\definecolor{lightgrey}{rgb}{0.925, 0.925, 0.925}
9
+
10
+\setlength{\topmargin}{-3cm}
11
+\setlength{\oddsidemargin}{-0.5cm}
12
+\setlength{\evensidemargin}{0cm}
13
+\setlength{\textwidth}{17.5cm}
14
+\setlength{\textheight}{24.5cm}
15
+%\setlength{\textwidth}{25cm}
16
+%\setlength{\textheight}{15cm}
17
+\setlength{\headheight}{84pt}
18
+
19
+\usepackage{fancyvrb}
20
+\usepackage{fvextra}
21
+%\usepackage{framed,color}
22
+%\newenvironment{modulelog}{\snugshade\Verbatim}{\endVerbatim\endsnugshade}
23
+\usepackage{adjustbox}
24
+\newenvironment{modulelog}%
25
+{\par\noindent\adjustbox{margin=0ex,bgcolor=shadecolor,margin=0ex}\bgroup\varwidth\linewidth\Verbatim}%
26
+{\endVerbatim\endvarwidth\egroup}
27
+%\usepackage{xcolor}
28
+
29
+\renewcommand{\baselinestretch}{1,2}
30
+\setlength{\parindent}{0pt}
31
+\setlength{\parskip}{9pt plus3pt minus3pt}
32
+
33
+\usepackage{listings}
34
+\usepackage{color}
35
+\definecolor{bg-partially-covered}{rgb}{1,1,0.6}    % light-yellow
36
+\definecolor{bg-uncovered}{rgb}{1,0.8,0.8}          % light-red
37
+\definecolor{bg-covered}{rgb}{0.95,1,0.95}          % very light-green
38
+\definecolor{bg-clean}{rgb}{1,1,1}                  % white
39
+\definecolor{mygreen}{rgb}{0,0.6,0}
40
+\definecolor{mygray}{rgb}{0.5,0.5,0.5}
41
+\definecolor{mymauve}{rgb}{0.58,0,0.82}
42
+\lstset{ %
43
+  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
44
+  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
45
+  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
46
+  breaklines=true,                 % sets automatic line breaking
47
+  captionpos=b,                    % sets the caption-position to bottom
48
+  commentstyle=\color{mygreen},    % comment style
49
+  deletekeywords={...},            % if you want to delete keywords from the given language
50
+  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
51
+  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
52
+  frame=none,	                   % adds a frame around the code
53
+  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
54
+  keywordstyle=\color{blue},       % keyword style
55
+  language=Octave,                 % the language of the code
56
+  morekeywords={*,...},            % if you want to add more keywords to the set
57
+  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
58
+  numbersep=5pt,                   % how far the line-numbers are from the code
59
+  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
60
+  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
61
+  showlines=true,
62
+  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
63
+  showstringspaces=false,          % underline spaces within strings only
64
+  showtabs=false,                  % show tabs within strings adding particular underscores
65
+  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
66
+  stringstyle=\color{mymauve},     % string literal style
67
+  tabsize=2,	                   % sets default tabsize to 2 spaces
68
+}
69
+\usepackage{hyperref}
70
+\usepackage{longtable}
71
+\usepackage{tabu}
72
+\usepackage{multicol}
73
+\usepackage{booktabs}
74
+\usepackage{graphicx}
75
+\usepackage{lastpage} % for the number of the last page in the document
76
+\usepackage{fancyhdr}
77
+\usepackage{xspace}
78
+
79
+
80
+% define commands for easy access
81
+\newcommand{\req}[2]{\begin{infoBox} \textbf{ #1:} #2 \end{infoBox}}
82
+\newcommand{\rfori}[1]{\textbf{Reason for Implementation:} #1 \\}
83
+\newcommand{\fitcrit}[1]{\textbf{Fitcriterion:} #1 \\}
84
+
85
+\fancyhf{}
86
+\renewcommand{\headrulewidth}{0pt}
87
+\renewcommand{\footrulewidth}{0pt}
88
+\lhead{\textcolor{gray}{}}
89
+\chead{\textcolor{gray}{ Requirement Specification for {\tt {{ macros.latex_filter(data.titel) }} }}}
90
+\rhead{\textcolor{gray}{}}
91
+\lfoot{\textcolor{gray}{}}
92
+\cfoot{\textcolor{gray}{}}
93
+\rfoot{\textcolor{gray}{\thepage\,/ \pageref{LastPage}}}
94
+
95
+\begin{document}
96
+

+ 13
- 0
templates/tex/macros.tex Zobrazit soubor

@@ -0,0 +1,13 @@
1
+{%- macro requirement_filter(text) -%}{{ text.replace('<', '$<$').replace('>', '$>$').replace('_', '\\_') }}
2
+{%- endmacro -%}
3
+{%- macro latex_filter(text) -%}{{ requirement_filter(text.replace('"', '\'')).replace('/xc2/xb0', '$^\circ$').replace('/', '/\\allowbreak ').replace('&', '\\allowbreak \\&').replace('->', '$\\rightarrow$').replace('<-', '$\\leftarrow$').replace('=>', '$\\Rightarrow$').replace('<=', '$\\leq$').replace('>=', '$\\geq$').replace('{', '\{').replace('}', '\}').replace('#', '\\#')}}
4
+{%- endmacro -%}
5
+
6
+{%- macro color_by_level(level) -%}{% if level <= 10 %}black{% else %}{% if level <= 20 %}green{% else %}{% if level <= 30 %}orange{% else %}red{% endif %}{% endif %}{% endif %}
7
+{%- endmacro -%}
8
+
9
+{%- macro bg_by_levelno(level) -%}{% if level <= 10 %}0.8 0.8 0.8{% else %}{% if level <= 20 %}0.8 0.95 0.8{% else %}{% if level <= 30 %}1 0.75 0.45{% else %}0.95 0.8 0.8{% endif %}{% endif %}{% endif %}
10
+{%- endmacro -%}
11
+
12
+{%- macro result(level) -%}{% if level <= 10 %}Info{% else %}{% if level <= 20 %}\textcolor{green}{Success}{% else %}{% if level <= 30 %}\textcolor{orange}{Warning}{% else %}\textcolor{red}{Failed}{% endif %}{% endif %}{% endif %}
13
+{%- endmacro -%}

+ 13
- 0
templates/tex/macros.tex~ Zobrazit soubor

@@ -0,0 +1,13 @@
1
+{%- macro requirement_filter(text) -%}{{ text.replace('<', '$<$').replace('>', '$>$') }}
2
+{%- endmacro -%}
3
+{%- macro latex_filter(text) -%}{{ requirement_filter(text).replace('\\', '/').replace('/xc2/xb0', '$^\circ$').replace('"', '\'').replace('/', '/\\allowbreak ').replace('&', '\\allowbreak \\&').replace('_', '\\_').replace('->', '$\\rightarrow$').replace('<-', '$\\leftarrow$').replace('=>', '$\\Rightarrow$').replace('<=', '$\\leq$').replace('>=', '$\\geq$').replace('{', '\{').replace('}', '\}').replace('#', '\\#')}}
4
+{%- endmacro -%}
5
+
6
+{%- macro color_by_level(level) -%}{% if level <= 10 %}black{% else %}{% if level <= 20 %}green{% else %}{% if level <= 30 %}orange{% else %}red{% endif %}{% endif %}{% endif %}
7
+{%- endmacro -%}
8
+
9
+{%- macro bg_by_levelno(level) -%}{% if level <= 10 %}0.8 0.8 0.8{% else %}{% if level <= 20 %}0.8 0.95 0.8{% else %}{% if level <= 30 %}1 0.75 0.45{% else %}0.95 0.8 0.8{% endif %}{% endif %}{% endif %}
10
+{%- endmacro -%}
11
+
12
+{%- macro result(level) -%}{% if level <= 10 %}Info{% else %}{% if level <= 20 %}\textcolor{green}{Success}{% else %}{% if level <= 30 %}\textcolor{orange}{Warning}{% else %}\textcolor{red}{Failed}{% endif %}{% endif %}{% endif %}
13
+{%- endmacro -%}

+ 15
- 0
templates/tex/requirement.tex Zobrazit soubor

@@ -0,0 +1,15 @@
1
+{%- import 'macros.tex' as macros %}
2
+{%- if 'Description' in item and item.Description != '' %}
3
+\paragraph{\xspace{}{{ macros.latex_filter(item.ID) }} ({{macros.latex_filter(item.Heading)}}):}
4
+
5
+{{ macros.requirement_filter(item.Description) }}
6
+
7
+{%- endif %}
8
+{%- if 'ReasonForImplementation' in item and item.ReasonForImplementation != '' %}
9
+
10
+Reason for Implementation: {{ macros.requirement_filter(item.ReasonForImplementation) }}
11
+{%- endif %}
12
+{%- if 'Fitcriterion' in item and item.Fitcriterion != '' %}
13
+
14
+Fitcriterion: {{ macros.requirement_filter(item.Fitcriterion) }}
15
+{%- endif %}

+ 32
- 0
templates/tex/requirement_specification.tex Zobrazit soubor

@@ -0,0 +1,32 @@
1
+{%- import 'macros.tex' as macros %}
2
+{%- include 'head.tex' %}
3
+{%- include 'titlepage.tex' %}
4
+\tableofcontents
5
+\newpage
6
+
7
+{%- for uid in data.uid_list_sorted %}
8
+	{% with item=data.item_dict[uid] %}
9
+		{%- if item.system_type_uid == '_4-K5EHYYEem_kd-7nxt1sg' %}
10
+			\section{ {{macros.latex_filter(item.Heading)}} }
11
+		{%- elif item.system_type_uid == '_MR7eNHYYEem_kd-7nxt1sg' %}
12
+			\subsection{\xspace{}{{ macros.latex_filter(item.ID) }}: {{macros.latex_filter(item.Heading)}} }
13
+			{%- if 'Description' in item and item.Description != '' %}
14
+				{{ macros.requirement_filter(item.Description) }}
15
+			 	{%- if 'ReasonForImplementation' in item and item.ReasonForImplementation != '' or 'Fitcriterion' in item and item.Fitcriterion != ''%}
16
+
17
+					\begin{tabu}{lX}
18
+					\toprule
19
+					{%- if 'ReasonForImplementation' in item and item.ReasonForImplementation != '' %}
20
+						\emph{Reason} & {{ macros.requirement_filter(item.ReasonForImplementation) }}\\
21
+					{%- endif %}
22
+					{%- if 'Fitcriterion' in item and item.Fitcriterion != '' %}
23
+						\emph{Fitcriterion} & {{ macros.requirement_filter(item.Fitcriterion) }}\\
24
+					{%- endif %}
25
+					\bottomrule
26
+					\end{tabu}
27
+				{%- endif %}
28
+		 	{%- endif %}
29
+		{%- endif %}
30
+	{% endwith %}
31
+{%- endfor %}
32
+{% include 'foot.tex' %}

+ 15
- 0
templates/tex/titlepage.tex Zobrazit soubor

@@ -0,0 +1,15 @@
1
+{%- import 'macros.tex' as macros %}
2
+\begin{titlepage}
3
+\date{\today}
4
+\title{
5
+	Requirement Specification for\\{\tt {{ macros.latex_filter(data.titel) }} }
6
+}
7
+\date{\today} 
8
+\maketitle
9
+\thispagestyle{empty}
10
+\newpage
11
+\end{titlepage}
12
+
13
+\setcounter{page}{1}
14
+\pagestyle{fancy}
15
+

Načítá se…
Zrušit
Uložit