-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathparse_exchange_versions.py
182 lines (133 loc) · 5.25 KB
/
parse_exchange_versions.py
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
#!/usr/bin/env python3
import requests
import lxml.html as lh
import json
import sys
from looseversion import LooseVersion
versions = {}
unique_versions = {}
def convert_short_name_to_long(short_name):
year = short_name[:4]
if '+' in short_name:
cu = short_name[4:short_name.index('+')]
patch = short_name[short_name.index('+')+1:]
return "Exchange Version %s %s + %s" % (year, cu, patch)
cu = short_name[4:]
return "Exchange Version %s %s" % (year, cu)
def convert_short_date_to_long(short_date):
months = {
"Jan": "January",
"Feb": "February",
"Mar": "March",
"Apr": "April",
"May": "May",
"Jun": "June",
"Jul": "July",
"Aug": "August",
"Sep": "September",
"Oct": "October",
"Nov": "November",
"Dec": "December",
}
m = short_date[:short_date.index('-')]
y = short_date[short_date.index('-')+1:]
return "%s, 20%s" % (months.get(m), y)
def nest_sub_versions():
# add entries without last part of the build
for version in unique_versions:
short_key = '.'.join(version.split('.', 3)[:-1])
if versions.get(short_key):
versions[short_key].append(unique_versions[version])
else:
versions[short_key] = [unique_versions[version]]
def parse_ms_docs_versions():
URL = "https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates"
page = requests.get(URL)
doc = lh.fromstring(page.content)
tr_elements = doc.xpath('//tr')
for i in range(1, len(tr_elements)):
row = tr_elements[i]
# If row is not of size 4, the //tr data is not from our table
if len(row) != 4 or row[0].text_content() == "" or row[0].text_content() == "Product name":
continue
# grab release details url if exists
url = None
if len(row[0]) > 0 and row[0][0].tag == 'a':
url = row[0][0].attrib['href'].strip()
# cells in row
# 0: Product name -> name
# 1: Release date -> release_date
# 2: Build number(short format) -> build
# 3: Build number(long format) -> build_long
v = {
'name': row[0].text_content().strip(),
'release_date': row[1].text_content().strip(),
'build': row[2].text_content().strip(),
'urls': [url] if url else [],
}
unique_versions[str(v['build'])] = v
def parse_eightwone_versions():
URL = "https://eightwone.com/references/versions-builds-dates/"
page = requests.get(URL)
doc = lh.fromstring(page.content)
tr_elements = doc.xpath('//tr')
for i in range(1, len(tr_elements)):
row = tr_elements[i]
# skip old versions and headers
if row[0].text_content() == "2019CU4" or row[0].text_content() == "Version":
continue
try:
name = convert_short_name_to_long(row[0].text_content().strip())
build = row[1].text_content().strip()
# fix some build numbers
if build == "8.0.685.25/24":
build = "8.0.685.25"
if build == "v2:15.0.712.24 (v1:15.0.712.22)":
build = "15.0.712.24"
if build == "15.2.1544.04":
build = "15.2.1544.4"
if build == "15.1.2044.8":
name = convert_short_name_to_long("2019CU17+KB581424")
if build == "15.1.1713.9":
name = convert_short_name_to_long("2016CU12+ KB4515832")
if build == "15.1.1713.8":
name = convert_short_name_to_long("2016 CU12 + KB4509409")
release_date = convert_short_date_to_long(
row[2].text_content().strip())
urls = []
if len(row[3]) > 0:
for a in row[3]:
if a.tag == 'a':
url = a.attrib['href'].strip()
# fix some broken urls
if url.lower().startswith('kb'):
url = "https://support.microsoft.com/kb/%s" % url[2:]
if url.lower().startswith('http://kb'):
url = "https://support.microsoft.com/kb/%s" % url[9:]
urls.append(url)
v = {
'name': name,
'release_date': release_date,
'build': build,
'urls': urls
}
# version not listed on Microsoft Docs
if (build not in unique_versions):
unique_versions[str(build)] = v
except Exception as ex:
print("error parsing version %s" % row[0].text_content().strip())
if __name__ == '__main__':
if (len(sys.argv[1:]) < 2):
exit("output files path missing")
versions_file = sys.argv[1]
unique_versions_file = sys.argv[2]
parse_ms_docs_versions()
parse_eightwone_versions()
unique_versions = {k: unique_versions[k] for k in sorted(
unique_versions, key=LooseVersion)}
nest_sub_versions()
# save files
with open(versions_file, "w") as output:
json.dump(versions, output, indent=4)
with open(unique_versions_file, "w") as output:
json.dump(unique_versions, output, indent=4)