-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompile_sheets.py
More file actions
296 lines (277 loc) · 8.69 KB
/
compile_sheets.py
File metadata and controls
296 lines (277 loc) · 8.69 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
#!/usr/bin/env python
#
#
# Requested by Drew-CodeRGV
# Created by ldartez
#
#
#
# compile master sheet with required information
# master sheet columns:
# * Manufacturer
# * Type
# * Part Number
# * Description
# * List Price
#
# Aruba Mapping:
# Manufacturer: Aruba
# Type: Sheet Name (Access points, Switches, Central Licensing)
# Part Number: Column A value
# Description: Column B value
# List Price: Column C value
#
# Cradlepoint Mapping:
# Manufacturer: Cradlepoint
# Type: Column B value
# Part Number: Column D value
# Description: Column G value
# List Price: Column F value
#
# Fortinet Mapping:
# Manufacturer: Fortinet
# Type: Sheet Name (FortiGate, Wireless Products)
# Part Number: Column B value
# Description: Column C value
# List Price: Column E value
#
# Meraki Mapping:
# Manufacturer: Meraki
# Type: Column B value
# Part Number: Column C value
# Description: Column D value
# List Price: Column F value
#
# SnapAV Mapping: (Note: use filter pre-selected for POWER)
# Manufacturer: SnapAV
# Type: Column A value
# Part Number: Column B value
# Description: Column C value
# List Price: Column J value
def filter_cells(filt, x):
'''Return true if x does not include any substrings in filt
'''
passing = True
for val in x:
for fv in filt:
if str(fv) in str(val):
passing = False
break
if not passing:
break
return passing
def parse_workbook_aruba(wbin):
'''
Aruba Mapping:
Manufacturer: Aruba
Type: Sheet Name (Access points, Switches, Central Licensing)
Part Number: Column A value
Description: Column B value
List Price: Column C value
Row Filters: 'Indoor Access Points', 'Mounting Brackets',
'Outdoor Access Points', None
'''
sheets = ['Access Points', 'Switches', 'Central Licensing']
row_filters = ['Indoor Access Points', 'Mounting Brackets',
'Outdoor Access Points', 'Part Number', 'Series', 'None' ]
mftr = 'Aruba'
result = []
for s in wbin.sheetnames:
if s not in sheets:
continue
else:
# process sheet rows
sheet = wbin[s]
for row in sheet.values:
filtpass = filter_cells(row_filters, list(row))
if not filtpass:
continue
else:
row_out = (mftr, sheet.title, row[0], row[1], row[2])
result.append(row_out)
return result
def parse_workbook_cradlepoint(wbin):
'''
Cradlepoint Mapping:
Manufacturer: Cradlepoint
Type: Column B value
Part Number: Column D value
Description: Column G value
List Price: Column F value
'''
sheets = ['USA']
row_filters = ['Cradlepoint USA MSRP', 'Company Confidential',
'Products']
types = ['Routers', 'Access Points', 'LTE Adapters', 'Performance Routers',
'Virtual Router', 'Mobile First Responder Packages',
'Gateways', 'FIPS', 'NetCloud', 'Threat Management',
'Internet Security', 'Feature Licenses', 'Modems',
'SIM-in-Box', 'Antennas', 'Cradlepoint Certified',
'Power Supplies', 'Miscellaneous', 'COR Series Routers',
'Accessories', 'AER Series Routers', 'Home Office',
'M2M']
mftr = 'Cradlepoint'
result = []
for s in wbin.sheetnames:
if s not in sheets:
continue
else:
# process sheet rows
sheet = wbin[s]
for row in sheet.values:
if str(row[3]) in ['None', 'Note', 'Part Number']:
continue
filtpass = filter_cells(types, str(row[1]).split())
if not filtpass:
cur_type = row[1]
row_out = (mftr, cur_type, row[3], row[6], row[5])
result.append(row_out)
return result
def parse_workbook_fortinet(wbin):
'''
Fortinet Mapping:
Manufacturer: Fortinet
Type: Sheet Name (FortiGate, Wireless Products)
Part Number: Column B value
Description: Column C value
List Price: Column E value
'''
sheets = ['FortiGate', 'Wireless Products']
row_filters = ['None', 'SKU', 'PRMA', 'Requires','HYPERLINK']
mftr = 'Fortinet'
result = []
for s in wbin.sheetnames:
if s not in sheets:
continue
else:
# process sheet rows
sheet = wbin[s]
for row in sheet.values:
filtpass = filter_cells(row_filters, str(row[1]).split())
if not filtpass:
continue
row_out = (mftr, s, row[1], row[2], row[4])
result.append(row_out)
return result
def parse_workbook_meraki(wbin):
'''
Meraki Mapping:
Manufacturer: Meraki
Type: Column B value
Part Number: Column C value
Description: Column D value
List Price: Column F value
'''
sheets = ['Report']
row_filters = ['Cisco']
mftr = 'Meraki'
result = []
for s in wbin.sheetnames:
if s not in sheets:
continue
else:
# process sheet rows
sheet = wbin[s]
# skip first few rows
for row in sheet.iter_rows(min_row=3, values_only=True):
if not filter_cells(row_filters, [row[1]]):
cur_type = str(row[1])
continue
row_out = (mftr, cur_type, row[2], row[3], row[5])
result.append(row_out)
return result
def parse_workbook_snapav(wbin):
'''
SnapAV Mapping: (Note: use filter pre-selected for POWER)
Manufacturer: SnapAV
Type: Column A value
Part Number: Column B value
Description: Column C value
List Price: Column J value
'''
sheets = ['Sheet 1']
row_filters = ['Cisco']
mftr = 'SnapAV'
result = []
for s in wbin.sheetnames:
if s not in sheets:
continue
else:
# process sheet rows
sheet = wbin[s]
# skip first few rows
for row in sheet.iter_rows(values_only=True):
if not 'Power' == str(row[0]):
continue
row_out = (mftr, row[0], row[1], row[2], row[9])
result.append(row_out)
return result
if __name__ == "__main__":
import argparse
from os.path import abspath, basename, isdir, isfile, exists, join
from os import walk, getcwd
from openpyxl import load_workbook, Workbook
from glob import glob
p = argparse.ArgumentParser()
p.add_argument('-o', '--output', default='master.xlsx',
help='path to output file')
p.add_argument('infiles', nargs='+')
args = p.parse_args()
fnames = []
for fin in args.infiles:
if not exists(fin):
raise ValueError("file not found: {}".format(fin))
elif isdir(fin):
flist = glob(join(fin,'*.xlsx'))
for f in flist:
if not f in fnames:
fnames.append(f)
elif isfile(fin):
if not fin in fnames:
fnames.append(fin)
dout = []
for f in fnames:
if 'aruba' in basename(f).lower():
msg = "Processing Aruba file: {}".format(f)
print(msg)
wb = load_workbook(f)
rows = parse_workbook_aruba(wb)
dout.extend(rows)
wb.close()
elif 'cradlepoint' in basename(f).lower():
msg = "Processing Cradlepoint file: {}".format(f)
print(msg)
wb = load_workbook(f)
rows = parse_workbook_cradlepoint(wb)
dout.extend(rows)
wb.close()
elif 'fortinet' in basename(f).lower():
msg = "Processing Fortinet file: {}".format(f)
print(msg)
wb = load_workbook(f)
rows = parse_workbook_fortinet(wb)
dout.extend(rows)
wb.close()
elif 'meraki' in basename(f).lower():
msg = "Processing Meraki file: {}".format(f)
print(msg)
wb = load_workbook(f)
rows = parse_workbook_meraki(wb)
dout.extend(rows)
wb.close()
elif 'snapav' in basename(f).lower():
msg = "Processing SnapAV file: {}".format(f)
print(msg)
wb = load_workbook(f)
rows = parse_workbook_snapav(wb)
dout.extend(rows)
wb.close()
wbout = Workbook()
wsout = wbout.active
hdr = ('Manufacturer', 'Type', 'Part Number', 'Description', 'List Price')
wsout.append(hdr)
if dout:
for r in dout:
wsout.append(r)
wbout.save(args.output)
wbout.close()