forked from gnachman/iterm2-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_downloads.py
executable file
·171 lines (144 loc) · 5.41 KB
/
generate_downloads.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
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
import os
import os.path, time
import re
import glob
import sys
print '''---
layout: default
title: Downloads - iTerm2 - Mac OS Terminal Replacement
active-state: downloads
---
'''
def strip_end(text, suffix):
if not text.endswith(suffix):
return text
return text[:len(text)-len(suffix)]
# Compare version numbers of iTerm2 filenames.
def CompareZipFileNames(x, y):
origX = x
origY = y
preview = "-preview"
x = x.replace(preview, "")
y = y.replace(preview, "")
#print "Compare",x,"and",y,"originals:",origX,"and",origY
if x == y and preview in origX and not preview in origY:
# Non-preview succeeds preview. x < y
#print "lhs is preview, rhs is not"
return -1
elif x == y and not preview in origX and preview in origY:
# x > y
#print "lhs is not preview, rhs is preview"
return 1
xname = os.path.basename(os.path.normpath(x))
yname = os.path.basename(os.path.normpath(y))
xversion = re.sub(r"iTerm2.*?([0-9_*]+([-_][^.]+)?)\.zip", r"\1", xname)
yversion = re.sub(r"iTerm2.*?([0-9_*]+([-_][^.]+)?)\.zip", r"\1", yname)
xversion = xversion.replace("beta", "0")
yversion = yversion.replace("beta", "0")
xsubnumbers = re.sub(r"[0-9_]+(-.*)", r"", xversion)
ysubnumbers = re.sub(r"[0-9_]+(-.*)", r"", yversion)
if len(xsubnumbers) == 0: xsubnumbers = "0"
if len(ysubnumbers) == 0: ysubnumbers = "0"
xnumbers = map(int, xsubnumbers.split("_"))
ynumbers = map(int, ysubnumbers.split("_"))
i = 0
while (i < len(xnumbers) and i < len(ynumbers)):
if xnumbers[i] > ynumbers[i]:
return 1
if xnumbers[i] < ynumbers[i]:
return -1
i += 1
if len(xnumbers) > len(ynumbers):
return 1
elif len(xnumbers) < len(ynumbers):
return -1
return cmp(yversion, xversion)
def Metadata(zip, metadataType, onError=None):
basename = os.path.splitext(zip)[0]
name = basename + "." + metadataType
try:
return open(name, "r").read()
except:
if onError is None:
return os.path.split(basename)[1]
else:
return onError
def Summary(zip):
return Metadata(zip, "summary")
def Description(zip):
return Metadata(zip, "description", onError="")
def ChangeLog(zip):
content = Metadata(zip, "changelog", onError="")
if len(content):
id = abs(hash(zip))
content = \
'''<p><a href="javascript:showId('%s')" id='show%s'>▸ Show Changelog</a>
<a href="javascript:hideId('%s')" id='hide%s' style="display: none">▾ Hide Changelog</a>
<pre id="changelist%s" style="display: none">%s</pre></p>''' % (id, id, id, id, id, content)
return content
BASE=os.environ["HOME"] + "/iterm2.com/downloads"
# Name, path component, description, array of substrings delineating tracks which always includes the empty string.
DOWNLOADS_PATHS=[("Stable Releases", "stable", "Stable releases update rarely but have no serious bugs.", [ "" ]),
("Test Releases", "beta", "Test releases update many times a year and are occasionally unstable.", [ "3_1_" ]), ]
j = 0
for sectionName,path,note,tracks in DOWNLOADS_PATHS:
print "<h3>" + sectionName + '</h3><hr style="margin-top: 0pt; margin-bottom: 4pt" />'
if note is not None:
print "<p>"
print note
print "</p>"
all_zips = glob.glob(BASE + "/" + path + "/*.zip")
all_zips.sort(cmp=CompareZipFileNames, reverse=True)
zips_by_track = { }
# Split up zip files into tracks. Each time the set of all_zips is shrunk. Whatever's left goes in the catchall track.
for track in tracks:
if track != "":
filtered = filter(lambda zip: track in zip, all_zips)
zips_by_track[track] = list(filtered)
all_zips = filter(lambda zip: track not in zip, all_zips)
zips_by_track[""] = list(all_zips)
for track in tracks:
track_zips = zips_by_track[track]
zips = [ track_zips[0] ]
remainder = track_zips[1:]
remainder.sort(cmp=CompareZipFileNames, reverse=True)
zips += remainder
i = 0
haveArchive = False
for zip in zips:
if i == 1:
haveArchive = True
key = "older_%d" % j
j += 1
print '''<p><a href="javascript:showId('%s')" id='show%s'>▸ Show Older Versions</a>
<a href="javascript:hideId('%s')" id='hide%s' style="display: none">▾ Hide Older Versions</a>
<div id="changelist%s" style="margin-left: 15pt; display: none"><h3>Older %s</h3>''' % (key, key, key, key, key, sectionName)
i += 1
name = os.path.split(zip)[1]
print '<h4 style="margin-top: 4pt"><a href="https://iterm2.com/downloads/' + path + '/' + name + '"><img src="/images/Download.png" width=100 height=27 style="padding-right: 10pt">' + Summary(zip) + '</a></h4>'
descr = Description(zip)
if len(descr) > 0:
print "<p>"
print descr
print '<br>'
cl = ChangeLog(zip)
if len(cl):
print cl
print "</p>"
if haveArchive:
print '''</div>'''
print '''
<h3>Nightly Builds</h3>
<hr style="margin-top: 0pt; margin-bottom: 4pt" />
A nightly build is made at midnight Pacific time on days where a change was committed. The change log may be seen <a href=\"https://github.com/gnachman/iTerm2/commits/master\">on Github</a>. Nightly builds sometimes have serious bugs.
</p>
<h4 style="margin-top: 4pt">
<a href="/nightly/latest">
<img src="/images/Download.png" width=100 height=35 style="padding-right: 10pt">Latest nightly build
</a></h4>
<p>
Older nightly builds may be found in the <a href="/downloads/nightly">nightly build archives.</a>
</p>
'''