]>
Commit | Line | Data |
---|---|---|
dd8152dd MT |
1 | #!/usr/bin/python |
2 | ||
3 | import os | |
4 | import time | |
5 | ||
6 | import web | |
7 | import web.elements | |
1101f3b4 | 8 | import web.javascript |
dd8152dd MT |
9 | |
10 | from web.info import Info | |
11 | info = Info() | |
12 | ||
13 | def size(file): | |
14 | size = os.path.getsize(file) | |
15 | suffixes = [("B",2**10), ("K",2**20), ("M",2**30), ("G",2**40), ("T",2**50)] | |
16 | for suf, lim in suffixes: | |
17 | if size > lim: | |
18 | continue | |
19 | else: | |
20 | return "%s%s" % (round(size/float(lim/2**10),2), suf) | |
21 | ||
22 | ||
23 | class Build(object): | |
24 | def __init__(self, path, basedir, url): | |
25 | self.path = path | |
26 | self.basedir = basedir | |
27 | self.url = os.path.join(url, path[len(basedir)+1:]) | |
28 | ||
29 | # Read .buildinfo | |
30 | f = open("%s/.buildinfo" % path) | |
31 | self.info = f.readlines() | |
32 | f.close() | |
33 | ||
34 | def __repr__(self): | |
35 | return "<Build %s>" % self.path | |
36 | ||
37 | def __cmp__(self, other): | |
38 | return cmp(float(other.get("date")), float(self.get("date"))) | |
39 | ||
40 | def get(self, key): | |
41 | key = key.upper() + "=" | |
42 | for line in self.info: | |
43 | if line.startswith(key): | |
44 | return line.split("=")[1].rstrip("\n") | |
45 | return None | |
46 | ||
47 | @property | |
48 | def hostname(self): | |
49 | return self.get("hostname") | |
50 | ||
51 | @property | |
52 | def release(self): | |
53 | return self.get("release") | |
54 | ||
55 | @property | |
56 | def date(self): | |
57 | return time.strftime("%Y-%m-%d %H:%M", time.localtime(float(self.get("date")))) | |
58 | ||
59 | @property | |
60 | def arch(self): | |
61 | return self.get("arch") | |
62 | ||
63 | @property | |
64 | def duration(self): | |
65 | if not self.get("duration") or self.get("duration") == "": | |
66 | return "--:--" | |
67 | return time.strftime("%H:%M", time.gmtime(float(self.get("duration")))) | |
68 | ||
69 | @property | |
70 | def iso(self): | |
71 | return self.get("iso") | |
72 | ||
73 | @property | |
74 | def packages(self): | |
f56af148 MT |
75 | path = "%s/packages_%s" % (self.path, self.arch,) |
76 | if not os.path.exists(path): | |
77 | return [] | |
78 | return os.listdir(path) | |
dd8152dd MT |
79 | |
80 | @property | |
81 | def pxe(self): | |
82 | dir = "/srv/www/ipfire.org/pxe" | |
83 | for iso in os.listdir(dir): | |
84 | # Skip non-iso files | |
85 | if not iso.endswith(".iso"): | |
86 | continue | |
87 | if os.readlink(os.path.join(dir, iso)) == os.path.join(self.path, self.iso): | |
88 | return "[PXE]" | |
89 | return "" | |
90 | ||
91 | ||
92 | class Content(web.Content): | |
93 | def __init__(self): | |
94 | web.Content.__init__(self) | |
95 | ||
96 | self.builds = [] | |
97 | for location in info["nightly_builds"]: | |
98 | # Only process correctly configured locations | |
99 | if not location.has_key("path") or not location.has_key("url"): | |
100 | continue | |
101 | ||
102 | # Continue if path does not exist | |
103 | if not os.path.exists(location["path"]): | |
104 | continue | |
105 | ||
106 | for (dir, subdirs, files) in os.walk(location["path"]): | |
107 | if not os.path.exists("%s/.buildinfo" % dir): | |
108 | continue | |
109 | self.builds.append(Build(dir, location["path"], location["url"])) | |
110 | self.builds.sort() | |
111 | ||
112 | def __call__(self, lang): | |
113 | today = time.strftime("%A, %Y-%m-%d", time.localtime()) | |
114 | last_day = "" | |
115 | ||
116 | ret = """<h3>Nightly builds</h3> | |
117 | <table id="builds"> | |
118 | <!-- <thead> | |
119 | <tr> | |
120 | <th> </th> | |
121 | <th>Release</th> | |
122 | <th>Host & Date</th> | |
123 | <th>Download</th> | |
124 | </tr> | |
125 | </thead> --> | |
126 | <tbody>""" | |
127 | ||
128 | # if there are no builds | |
129 | if not self.builds: | |
130 | ret += """<tr class="headline"><td colspan="6">There are currently no builds available.</td></tr>""" | |
131 | ||
132 | else: | |
133 | for build in self.builds: | |
134 | # write headers | |
135 | day = time.strftime("%A, %Y-%m-%d", time.localtime(float(build.get("date")))) | |
136 | if day != last_day: | |
137 | if day == today: | |
138 | ret += """<tr class="headline"><td colspan="5">Today</td></tr>""" | |
139 | else: | |
140 | ret += """<tr class="headline"><td colspan="5"> <br /> <br />%s</td></tr>""" % day | |
141 | last_day = day | |
142 | ||
1101f3b4 | 143 | ret += """<tr class="build"> |
3b7135e7 | 144 | <td><a href="%s" target="_blank">""" % build.url |
1101f3b4 | 145 | |
dd8152dd | 146 | if day == today: |
1101f3b4 | 147 | ret += """<img src="/images/icons/ipfire.png" alt="IPFire" /></a></td>""" |
dd8152dd | 148 | else: |
1101f3b4 | 149 | ret += """<img src="/images/icons/ipfire_sw.png" alt="IPFire" /></a></td>""" |
dd8152dd MT |
150 | |
151 | ret += """\ | |
dd8152dd MT |
152 | <td> <br /> |
153 | <strong>%(release)s</strong> (%(arch)s) %(pxe)s<br /> | |
154 | <a href="%(url)s/%(iso)s">%(iso)s</a> %(size_iso)s</td> | |
155 | <td> <br /> | |
156 | %(hostname)s<br /> | |
157 | %(date)s [%(duration)sh]</td> | |
158 | <td class="packages">%(num_packages)s <a href="%(url)s/packages_%(arch)s/" target="_blank">[PAKS]</a></td> | |
159 | </tr>""" % { "release" : build.release, | |
160 | "hostname" : build.hostname, | |
161 | "arch" : build.arch, | |
162 | "date" : build.date, | |
163 | "duration" : build.duration, | |
164 | "url" : build.url, | |
165 | "iso" : build.iso, | |
166 | "size_iso" : size(os.path.join(build.path, build.iso)), | |
167 | "num_packages" : len(build.packages), | |
168 | "pxe" : build.pxe } | |
169 | ||
170 | ret += """\ | |
171 | </tbody> | |
172 | </table>""" | |
173 | ||
174 | return ret | |
175 | ||
176 | ||
177 | page = web.Page() | |
178 | page.content = Content() | |
179 | page.sidebar = web.elements.DevelopmentSidebar() | |
1101f3b4 MT |
180 | |
181 | ### Disabled because it looks awful | |
182 | #page.javascript = web.javascript.Javascript(jquery=1) | |
183 | #page.javascript.jquery_plugin("alternate") | |
184 | #page.javascript.write(""" | |
185 | # <script type="text/javascript"> | |
186 | # $(function() { | |
187 | # $("#builds tbody tr.build").alternate({odd:'odd', even:'even'}); | |
188 | # }); | |
189 | # </script> | |
190 | #""") |