Passed
Pull Request — develop (#458)
by
unknown
02:49
created

valMatrix   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 209
Duplicated Lines 13.88 %

Importance

Changes 0
Metric Value
eloc 126
dl 29
loc 209
rs 10
c 0
b 0
f 0
wmc 10

3 Functions

Rating   Name   Duplication   Size   Complexity  
C _publish_lines() 0 150 5
A _lines_valMatrix_css() 0 5 2
A publish_Matrix() 29 29 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# Create an html output of the validationMatrix
2
3
import os
4
from doorstop import common
5
from doorstop.common import DoorstopError
6
from doorstop.core.types import iter_documents, iter_items, is_tree, is_item
7
from doorstop import settings
8
from datetime import datetime
9
10
# Create path to css file for verification matrix
11
Matrix_Unchanged_CSS = os.path.join(os.path.dirname(__file__),'..', 'files', 'valMatrix.css')
12
13
14
15
log = common.logger(__name__)
16
17
18
19 View Code Duplication
def publish_Matrix(obj, path): 
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
21
    """Publish validation matrix as html file.
22
23
    :param obj: (1) Item, list of Items, Document or (2) Tree
24
    :param path: (1) output file path or (2) output directory path
25
    
26
27
    #:raises: :class:`doorstop.common.DoorstopError` for unknown file formats
28
29
    
30
31
    """
32
    # Set file output extension to html 
33
    extension = '.html'
34
    
35
    if  is_tree(obj):     
36
        for tmp_obj, tmp_path in iter_documents(obj, path, extension):       
37
            # Make file and write created lines into it
38
            common.create_dirname(tmp_path)      
39
            lines = _publish_lines(tmp_obj)
40
            common.write_lines(lines,tmp_path)
41
42
    else: 
43
        path = os.path.join(path, obj.prefix + extension)
44
        # Make file and write created lines into it
45
        common.create_dirname(path)  
46
        lines = _publish_lines(obj)
47
        common.write_lines(lines,path)
48
    
49
        
50
51
52
def _publish_lines(tmp_obj):
53
    ''' 
54
    Yield lines for an html validation Matrix
55
56
    param tmp_object: tree like object to publish 
57
    
58
    '''
59
60
    # Create html-files 
61
   
62
    yield '<!DOCTYPE html>'
63
    yield '<html lang="en">'
64
    yield '<head>'
65
    yield '<title>validation matrix</title>'
66
67
    yield '<style type="text/css">'
68
    yield from _lines_valMatrix_css() 
69
    yield '</style>'
70
    yield '</head>'
71
72
    yield '<body>'
73
    yield '<div class="background-color"></div>'
74
    yield '<div class="Center-align">'
75
    yield '<h1 >Validation Matrix</h1>'
76
    yield '</div>'
77
78
    # Print button
79
    yield '<button onclick="Print()">Print</button>'
80
    yield '<div class = "float-right"><strong>Hit "ctrl+s" to save changes!</strong></div>'
81
82
    yield '<table width=50% >'
83
    yield '<tbody>'
84
85
    yield '<tr>'
86
    yield '<td>Project</td>'
87
    # Project
88
    yield '<td contenteditable="true">'
89
    yield ''
90
    yield '</td>'
91
    yield '</tr>'
92
93
    yield '<tr>'
94
    yield '<td>Validation Matrix for</td>'
95
    # Name for document of validation
96
    yield '<td>'
97
    yield tmp_obj.prefix
98
    yield '</td>'
99
    yield '</tr>'
100
101
    yield '<tr>'
102
    yield '<td>Date</td>'
103
    # Date of creation  
104
    yield '<td>'
105
    yield datetime.today().strftime('%d/%m/%Y')
106
    yield '</td>'
107
    yield '</tr>'
108
109
    yield '<tr>'
110
    yield '<td>Owner</td>'
111
    # Owner 
112
    yield '<td contenteditable="true">'
113
    yield ''
114
    yield '</td>'
115
    yield '</tr>'
116
117
    yield '<tr>'
118
    yield '<td>Issue</td>'
119
    # Issue 
120
    yield '<td contenteditable="true">'
121
    yield ''
122
    yield '</td>'
123
    yield '</tr>'
124
125
    yield '</tbody>'
126
    yield '</table>'
127
    
128
    
129
130
    yield '<table width=100% >'
131
    yield '<tbody>'
132
    yield '<tr>'
133
    yield '<th colspan="2" width=20%>Requirements</th>'
134
    yield '<th colspan="4" width=40%>Traceabillity</th>'
135
    yield '<th colspan="4" width=40%>Validation</th>'
136
    yield '</tr>'
137
138
    yield '<tr>'
139
    yield '<th colspan="2" width=20%>Req. ID</th>'
140
    yield '<th colspan="2" width=20%>Parent req. ID</th>'
141
    yield '<th colspan="2" width=20%>Rationale</th>'
142
    yield '<th colspan="1" width=10%>Validation Method</th>'
143
    yield '<th colspan="2" width=20%>Validation evidence Method</th>'
144
    yield '<th colspan="1" width=10%>Conclusion</th>'
145
    yield '</tr>'
146
    
147
    
148
    for item in tmp_obj:
149
        if item.Is_Req:
150
            yield '<tr>'
151
152
            # Write values in Req.ID
153
            yield '<td colspan="2" width=20% contenteditable="false">'
154
            yield str(item.uid)
155
            yield '</td>'
156
157
            # Write value for parent req. ID
158
            yield '<td colspan="2" width=20% contenteditable="false">'
159
            if not len(item.links) == 0:
160
                for link in item.links:
161
                    yield str(link) + '<br>'
162
            else:
163
                yield ''
164
            yield '</td>'
165
166
            # Write rationale
167
            yield '<td colspan="2" width=20% contenteditable="fasle">'
168
            yield str(item.SPEC_RATIONALE) 
169
            yield '</td>'
170
171
            # Write value for Validation Method 
172
            yield '<td colspan="1" width=10% contenteditable="true">'
173
            yield '<div class="Center-align">'
174
            yield str(item.Validation_Mean)
175
            yield '</div>'
176
            yield '</td>'
177
178
179
            # Write validation evidence reference 
180
            yield '<td colspan="2" width=20% contenteditable="true">'
181
            yield ''  # Manul user entry 
182
            yield '</td>'
183
184
            # Write status/conclusion of requirement
185
            yield '<td colspan="1" width=20% contenteditable="true">'
186
            yield '<div class="Center-align">'
187
            yield str(item.SPEC_STATUS)
188
            yield '</div>'
189
            yield '</td>'
190
191
            yield '</tr>'
192
193
    yield '</tbody>'
194
    yield '</tabele>'
195
196
    # Function for the Print Button
197
    yield '<script>function Print() {window.print();}</script>'
198
    yield '<script>function Safe() {window.safe();}</script>'
199
200
    yield '</body>'
201
    yield '</html>'
202
203
204
def _lines_valMatrix_css():
205
    yield ''
206
    for line in common.read_lines(Matrix_Unchanged_CSS):
207
        yield line.rstrip()
208
    yield ''
209