-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakesheet.py
More file actions
405 lines (309 loc) · 18.3 KB
/
makesheet.py
File metadata and controls
405 lines (309 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
'''
This class has d
'''
import xlsxwriter
from service_network.excelerator import burnFinalexceldata
class makeExcel:
def __init__(self,):
self.search_command = "NF"
def prepareSheet(self,logpath,totFields,extlist):
self.extList = extlist
sucFile = None
self.totalFields = totFields
self.rowsWritten =0
localrow = 0
self.subrows = 0
self.writtenFlag = 'N'
self.max_rows_written = 0
self.burnSheet = burnFinalexceldata.burnfinalExcel()
self.row =1
self.FieldsDict = { }
try :
self.mybook = xlsxwriter.Workbook(logpath + "\\Data Sheet.xlsx")
self.mySheet = self.mybook.add_worksheet()
self.style = self.mybook.add_format({'bold': True})
self.style.set_font_size(11)
self.style.set_bg_color('yellow')
self.style.set_font_color('black')
self.white_style_interface_txt = self.mybook.add_format({'bold':True, 'font_color': 'black'})
self.orange_style_txt = self.mybook.add_format({'bold':False, 'font_color': 'red'})
self.green_style_txt = self.mybook.add_format({'bold':False,'font_color' : 'green' })
col =0
for col in range(len(self.extList)):
if self.extList[col] == "Serial Number General" or self.extList[col] == "Serial Number Audit" :
self.mySheet.write(chr(col+65) + str(self.row), "Serial Number", self.style)
else:
self.mySheet.write(chr(col+65) + str(self.row), self.extList[col], self.style)
self.mySheet.set_column('A:' + chr(col + 65), 25)
self.style = self.mybook.add_format({'bold': False})
self.style.set_font_size(11)
#mybook.close()
except Exception as ex :
print(ex)
return False
try :
sucFile = open(logpath + "\\Final_log.txt" , 'r')
finallog_content = sucFile.readlines()
sucFile.close()
for line in finallog_content:
if ": Success" in line :
ipadd = line[ : line.rfind(':')]
ipadd = ipadd.strip()
self.row = self.row + 1
self.prepareData(ipadd,logpath)
except Exception as ex:
print(ex)
return False
self.mybook.close()
return True
def prepareData(self,ipadd,logpath):
self.finalAttrib = []
item =0
matchStr ="NF"
self.max_rows_written = 0
self.Auditvartouched = "N"
self.network_attrib_touched = "No"
self.search_attrib_touched = "No"
partNolist = []
hostname = matchStr = self.burnSheet.getHostinfo(logpath,ipadd)
for col in range(len(self.extList)):
if self.extList[col] =="Hostname":
hostnamecol = chr(col + 65)
break
# reading log file , passing list to far method
try :
sucFile = open(logpath + "\\" + ipadd + ".txt" , 'r')
self.sucfilecontent = sucFile.readlines()
sucFile.close()
except Exception as ex:
print("There is something wrong in make sheet method , log file opening section")
print(ex)
sucFile.close()
return False
for item in range(len(self.extList)):
matchStr = "NF"
if self.extList[item] == "IP Address":
self.finalAttrib.append(ipadd)
self.writeSheet("IP Address")
if self.extList[item] =="Hostname":
matchStr = self.burnSheet.getHostinfo(logpath,ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("Hostname")
if self.extList[item] == "Model":
matchStr = self.burnSheet.burnModel.getModelInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("Model")
if self.extList[item] == "Parent / Neighbor Device" :
matchStr= self.burnSheet.togetParentDevice.write_parent_dev_info(logpath, ipadd,self.sucfilecontent)
self.finalAttrib.append(matchStr)
self.writeSheet("Parent / Neighbor Device")
if self.extList[item] == "Serial Number General":
matchStr = self.burnSheet.getGeneralSerialnoInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
self.writeSheet("Serial Number General")
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
if self.extList[item] == "OS version":
matchStr = self.burnSheet.burnImageinfo.getImageInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
self.writeSheet("OS version")
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
if self.extList[item] == "Template version":
matchStr = self.burnSheet.templatever.getTemplateversion(logpath, ipadd)
self.finalAttrib.append(matchStr)
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
self.writeSheet("Template version")
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
if self.extList[item] == "Template Name":
matchStr = self.burnSheet.toKnowtemplatename.getTemplateName(logpath, ipadd)
self.finalAttrib.append(matchStr)
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
self.writeSheet("Template Name")
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
if self.extList[item] == "Flash free bytes":
matchStr = self.burnSheet.getFlashfreeInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("Flash free bytes")
if self.extList[item] == "Last Config Date":
matchStr = self.burnSheet.lastConf.configChangeDateTimeInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("Last Config Date")
if self.extList[item] == "ASPR ACL present:Yes/No ?":
matchStr = self.burnSheet.toKnowASPRstatus.doIhaveASPRaclInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("ASPR ACL present:Yes/No ?")
if self.extList[item] == "Exception":
exceptionDetails = " "
matchStr,exceptionDetails= self.burnSheet.toknowExceptionStatus.doIhaveExceptioinInfo(logpath, ipadd)
self.finalAttrib.append(matchStr)
self.writeSheet("Exception")
if self.extList[item] == "Exception Details":
self.finalAttrib.append(exceptionDetails)
self.writeSheet("Exception Details")
if self.extList[item] == "Part Number":
col = 0
for col in range(len(self.extList)) :
if self.extList[col] == "Part Number":
colValue = chr(col + 65)
break
partNolist, self.rowsWritten = self.burnSheet.burnPartnum.getPartnoInfo(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname)
self.rowsWritten = self.rowsWritten - 1
self.row = self.row + self.rowsWritten
self.Auditvartouched = "Y"
if self.extList[item] == "Part Name":
col = 0
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Part Name":
colValue = chr(col + 65)
break
partNamelist, self.rowsWritten = self.burnSheet.burnPartnum.getPartnameInfo(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname)
self.rowsWritten = self.rowsWritten - 1
self.row = self.row + self.rowsWritten
self.Auditvartouched = "Y"
if self.extList[item] == "Serial Number Audit":
col = 0
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Serial Number Audit":
colValue = chr(col + 65)
break
partNolist, self.rowsWritten = self.burnSheet.burnauditserialDescr.getauditSerialnoInfo(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname)
self.rowsWritten = self.rowsWritten - 1
self.row = self.row + self.rowsWritten
self.Auditvartouched = "Y"
if self.extList[item] == "Description":
col = 0
if self.Auditvartouched == "Y":
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Description":
colValue = chr(col + 65)
break
descrList, self.rowsWritten = self.burnSheet.burnauditserialDescr.getDescriptionInfo(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname)
self.rowsWritten = self.rowsWritten - 1
self.row = self.row + self.rowsWritten
self.Auditvartouched = "Y"
# below section for network subnets handling under network tab:
if self.extList[item] == "MGMT VLAN" :
col = 0
#if self.network_attrib_touched == "Yes" :
# self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "MGMT VLAN":
colValue = chr(col + 65)
searchpat = "MGMT VLAN"
break
self.rowsWritten = self.burnSheet.vlans_subnets_engine.write_MDVO_vlan_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,searchpat,self.sucfilecontent)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten:
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.network_attrib_touched = "Yes"
if self.extList[item] == "Data VLAN" :
col = 0
if self.network_attrib_touched == "Yes" :
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Data VLAN" :
colValue = chr(col + 65)
searchpat = "DATA VLAN"
break
self.rowsWritten = self.burnSheet.vlans_subnets_engine.write_MDVO_vlan_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,searchpat,self.sucfilecontent)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten :
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.network_attrib_touched = "Yes"
if self.extList[item] == "Voice VLAN" :
col = 0
if self.network_attrib_touched == "Yes" :
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Voice VLAN" :
colValue = chr(col + 65)
searchpat = "VOICE VLAN"
break
self.rowsWritten = self.burnSheet.vlans_subnets_engine.write_MDVO_vlan_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,searchpat,self.sucfilecontent)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten :
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.network_attrib_touched = "Yes"
if self.extList[item] == "Wireless VLAN" :
col = 0
if self.network_attrib_touched == "Yes":
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Wireless VLAN" :
colValue = chr(col + 65)
searchpat = "WIRELESS VLAN all"
break
self.rowsWritten = self.burnSheet.vlans_subnets_engine.write_wireless_vlan_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,self.sucfilecontent)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten :
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.network_attrib_touched = "Yes"
if self.extList[item] == "Other VLAN" :
col = 0
if self.network_attrib_touched == "Yes" :
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Other VLAN" :
colValue = chr(col + 65)
searchpat = "Misc / Non Standard VLAN"
break
self.rowsWritten = self.burnSheet.vlans_subnets_engine.write_MDVO_vlan_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,searchpat,self.sucfilecontent)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten :
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.network_attrib_touched = "Yes"
# below section for handling search pattern :
if self.extList[item] == "Search Pattern" :
col = 0
if self.search_attrib_touched == "Yes" :
self.row = self.row - self.rowsWritten
for col in range(len(self.extList)) :
if self.extList[col] == "Search Pattern" :
colValue = chr(col + 65)
#searchpat = "Misc / Non Standard VLAN"
break
self.rowsWritten = self.burnSheet.search_command.write_pattern_info(logpath, ipadd,self.row ,colValue,self.mySheet,self.style,hostnamecol,hostname,self.search_command,self.sucfilecontent,self.orange_style_txt,self.green_style_txt,self.white_style_interface_txt,col)
#self.rowsWritten = self.rowsWritten - 1
if self.rowsWritten < self.max_rows_written :
self.rowsWritten = self.max_rows_written
if self.max_rows_written < self.rowsWritten :
self.max_rows_written = self.rowsWritten
self.row = self.row + self.rowsWritten
self.search_attrib_touched = "Yes"
#if self.Auditvartouched == "Y":
# self.row = self.row + self.rowsWritte
return self.finalAttrib
def writeSheet(self,field):
col =0
for col in range(len(self.finalAttrib)):
if self.extList[col] == field:
self.mySheet.write(chr(col+65) + str(self.row), self.finalAttrib[col], self.style)