This repository was archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpatch_spreadsheet_to_json.py
More file actions
executable file
·93 lines (69 loc) · 2.75 KB
/
Copy pathpatch_spreadsheet_to_json.py
File metadata and controls
executable file
·93 lines (69 loc) · 2.75 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
#!/usr/bin/env python3
import json
import os
from collections import defaultdict
import gspread # this is a modified version! see requirements.txt
import logging
# https://docs.google.com/spreadsheets/d/1MTbU9Bq130zrrsJwLIB9d8qnGfYZnkm4jBlfNaBF19M/pubhtml
SPREADSHEET_ID = '1MTbU9Bq130zrrsJwLIB9d8qnGfYZnkm4jBlfNaBF19M'
PATH = os.path.dirname(os.path.realpath(__file__))
debug = False
if debug:
import requests_cache
requests_cache.install_cache(
'cache',
backend='sqlite',
allowable_methods=('GET', 'POST'),
allowable_codes=(200, 401, 403, 404, 502, 503, 301, 302, 303),
)
def find_patches_for_row(row, patches):
required_patches = set()
for col_id, cell in enumerate(row):
if cell in ('', 'Not Required', 'Not Supported', 'Under investigation', 'Ask support'):
continue
elif cell.startswith('Replaced by'):
continue
elif cell == 'Required':
patch = patches[col_id]
elif cell.startswith('Use '):
patch = cell[4:]
else:
logging.warning("Unsupported status: %s" % cell)
continue
# requires different patch id's per mag version, so not usable for automatic parsing
if 'APPSEC' in patch:
continue
patch = patch.replace(' V', ' v')
required_patches.add(patch)
# sort patches alphabetically on patch version and take the latest (v2 over v1.1)
return sorted(required_patches)
gc = gspread.public()
document = gc.open_by_key(SPREADSHEET_ID)
giant_blob = {}
for sheet in document.worksheets():
matrix = sheet.get_all_values()
if matrix[1][0] != 'Version':
# not a M1 CE or EE sheet
continue
edition = matrix[2][0] # Community or Enterprise
patches = matrix[1][2:] # skip first 2 cols
giant_blob[edition] = {}
for row_id in range(3, 50):
version = matrix[row_id][0]
# break on first empty row
if not version:
break
required_patches = find_patches_for_row(matrix[row_id][2:], patches)
giant_blob[edition][version] = required_patches
try:
assert 'SUPEE-8788 v2' in giant_blob['Community']['1.7.0.0']
assert 'SUPEE-6788' in giant_blob['Enterprise']['1.6.x']
assert 'SUPEE-7405 v1.1' in giant_blob['Enterprise']['1.14.2.1']
assert 'SUPEE-7405' in giant_blob['Enterprise']['1.14.2.1']
assert 'SUPEE-6079' not in giant_blob['Enterprise']['1.14.2.0']
assert 'SUPEE-3762' not in giant_blob['Community']['1.4.0.0']
except AssertionError:
print("Patch parsing didn't work out. Result is:\n%s" % json.dumps(giant_blob, indent=2))
raise
with open(PATH + '/../static/required_magento_patches.json', 'w') as f:
f.write(json.dumps(giant_blob, indent=2, sort_keys=True))