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

verMatrix._publish_lines()   C

Complexity

Conditions 5

Size

Total Lines 151
Code Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 100
nop 1
dl 0
loc 151
rs 6.5333
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# Create an html output of the verificationMatrix
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 verification 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 verification 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>verification 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 >Verification 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>Verification Matrix for</td>'
95
    # Name for document of verification
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%>Verification</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%>Verification Method</th>'
143
    yield '<th colspan="2" width=20%>Verification evidence Method</th>'
144
    yield '<th colspan="1" width=10%>Conclusion</th>'
145
    yield '</tr>'
146
    
147
    
148
    for item in tmp_obj:
149
        #Chek ob es sich bei dem Item auch um ein Requirment handelt ...
150
        if item.Is_Req:
151
            yield '<tr>'
152
153
            # write values in Req.ID
154
            yield '<td colspan="2" width=20% contenteditable="false">'
155
            yield str(item.uid)
156
            yield '</td>'
157
158
            #write value for parent req. ID
159
            yield '<td colspan="2" width=20% contenteditable="false">'
160
            if not len(item.links) == 0:
161
                for link in item.links:
162
                    yield str(link) + '<br>'
163
            else:
164
                yield ''
165
            yield '</td>'
166
167
            # write rationale
168
            yield '<td colspan="2" width=20% contenteditable="false">'
169
            yield str(item.Verification_Rationale) 
170
            yield '</td>'
171
172
            #write value for Verification Method 
173
            yield '<td colspan="1" width=10% contenteditable="true">'
174
            yield '<div class="Center-align">'
175
            yield str(item.Verification_Mean)
176
            yield '</div>'
177
            yield '</td>'
178
179
180
            #write Verification evidence reference 
181
            yield '<td colspan="2" width=20% contenteditable="true">'
182
            yield ''  # muss auch noch genauer spezifiziert werden
183
            yield '</td>'
184
185
            #write status/conclusion of requirement
186
            yield '<td colspan="1" width=20% contenteditable="true">'
187
            yield '<div class="Center-align">'
188
            yield str(item.Verification_Status)
189
            yield '</div>'
190
            yield '</td>'
191
192
            yield '</tr>'
193
194
    yield '</tbody>'
195
    yield '</tabele>'
196
197
    # Function for the Print Button
198
    yield '<script>function Print() {window.print();}</script>'
199
    yield '<script>function Safe() {window.safe();}</script>'
200
201
    yield '</body>'
202
    yield '</html>'
203
204
205
def _lines_valMatrix_css():
206
    yield ''
207
    for line in common.read_lines(Matrix_Unchanged_CSS):
208
        yield line.rstrip()
209
    yield ''
210