forked from gnachman/iterm2-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_downloads.py
executable file
·63 lines (54 loc) · 1.75 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
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
import os
import os.path, time
import glob
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><br>''' % (id, id, id, id, id, content)
return content
BASE=os.environ["HOME"] + "/iterm2.com/downloads"
DOWNLOADS_PATHS=[("Stable Releases", "stable"),
("Test Releases", "beta"),
("Nightly builds", "nightly")]
LIMIT = { "stable": 1,
"beta": 2,
"nightly": 5 }
for sectionName,path in DOWNLOADS_PATHS:
print "<h3>" + sectionName + "</h3>"
zips = glob.glob(BASE + "/" + path + "/*.zip")
zips.sort(reverse=True)
i = 0
for zip in zips:
if i == LIMIT[path]:
break
i += 1
name = os.path.split(zip)[1]
print '<h4><a target="_blank" href="/downloads/' + path + '/' + name + '"><img src="/images/small-download.png" align="left"> ' + Summary(zip) + '</a></h4>'
print "<p>"
print Description(zip)
print '<br>'
cl = ChangeLog(zip)
if len(cl):
print cl
print "</p>"
print "<br>"