-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-index
executable file
·71 lines (64 loc) · 1.68 KB
/
generate-index
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
#!/usr/bin/python
import os
DESCRIPTION_FILE_NAME = "description.html"
INDEX_FILE_NAME = "index.html"
INDEX_TEMPLATE = """
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<html>
<title>OGS Mahjong 2 web releases</title>
<body>
<h1>OGS Mahjong 2 web releases</h1>
<p>Source code repository is <a href="https://bitbucket.org/ogstudio-games/mahjong">here</a></p>
<p><strong>Note</strong>: click on image to run concrete version</p>
<table>
<tr>
<th>Screenshot</th>
<th>Version</th>
<th>Date</th>
<th>Topic</th>
<th>Description</th>
</tr>
{items}
</table>
</body>
</html>
"""
ITEM_TEMPLATE = """
<!-- {id} -->
<tr>
<td>
<a href="versions/{id}/mjin-player.html">
<img class="resize" src="versions/{id}/shot.png">
</a>
</td>
<td>{id}</td>
<td>{date}</td>
<td>{brief}</td>
<td>{long}</td>
</tr>
"""
VERSIONS_DIR = "versions"
def description(fileName):
lines = []
with open(fileName, "r") as f:
lines = f.readlines()
return lines
versions = sorted(os.listdir(VERSIONS_DIR))
contents = ""
for version in versions:
print("Processing version '{0}'".format(version))
# Read description.
fileName = "versions/{0}/description.html".format(version)
desc = description(fileName)
# Compose item.
contents += ITEM_TEMPLATE.format(
id = version,
date = desc[0],
brief = desc[1],
long = desc[2]
)
with open(INDEX_FILE_NAME, "w") as f:
fileContents = INDEX_TEMPLATE.format(items = contents)
f.write(fileContents)