]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/webapp/releases.py
Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire.org
[people/shoehn/ipfire.org.git] / www / webapp / releases.py
CommitLineData
81675874 1#!/usr/bin/python
2
befc2e59 3from helpers import Item, _stringify, json_loads
81675874 4
5class ReleaseItem(Item):
6 options = {
7 "iso" : {
8 "prio" : 10,
9 "desc" : "Installable CD image",
10 "url" : "http://download.ipfire.org/iso/",
ab66924a 11 "rem" : "Use this image to burn a CD and install IPFire from it.",
81675874 12 },
13 "torrent" : {
14 "prio" : 20,
15 "desc" : "Torrent file",
16 "url" : "http://download.ipfire.org/torrent/",
ab66924a 17 "rem" : "Download the CD image from the torrent network.",
81675874 18 },
c7a8c43a 19 "flash" : {
81675874 20 "prio" : 40,
c7a8c43a 21 "desc" : "Flash image",
81675874 22 "url" : "http://download.ipfire.org/iso/",
ab66924a 23 "rem" : "An image that is meant to run on embedded devices.",
81675874 24 },
c7a8c43a
MT
25 "alix" : {
26 "prio" : 41,
27 "desc" : "Alix image",
28 "url" : "http://download.ipfire.org/iso/",
29 "rem" : "Flash image where a serial console is enabled by default.",
30 },
81675874 31 "usbfdd" : {
32 "prio" : 30,
65e4c995 33 "desc" : "USB FDD image",
81675874 34 "url" : "http://download.ipfire.org/iso/",
ab66924a 35 "rem" : "Install IPFire from a floppy-formated USB key.",
81675874 36 },
37 "usbhdd" : {
38 "prio" : 30,
65e4c995 39 "desc" : "USB HDD image",
81675874 40 "url" : "http://download.ipfire.org/iso/",
ab66924a 41 "rem" : "If the floppy image doesn't work, use this image instead.",
81675874 42 },
43 "xen" : {
44 "prio" : 50,
65e4c995 45 "desc" : "Pregenerated Xen image",
81675874 46 "url" : "http://download.ipfire.org/iso/",
ab66924a 47 "rem" : "A ready-to-run image for Xen.",
81675874 48 },
49 }
50
51 @property
52 def downloads(self):
53 ret = []
54 for fileitem in self.args["files"]:
55 filetype = fileitem["type"]
56 ret.append(Item(
57 desc = self.options[filetype]["desc"],
58 file = fileitem["name"],
59 hash = fileitem.get("hash", None),
60 prio = self.options[filetype]["prio"],
ab66924a 61 rem = self.options[filetype]["rem"],
81675874 62 sha1 = fileitem.get("sha1", None),
63 type = filetype,
64 url = self.options[filetype]["url"] + fileitem["name"],
65 ))
66
67 ret.sort(lambda a, b: cmp(a.prio, b.prio))
68 return ret
69
70 for option in self.options.keys():
71 if not self.args["files"].has_key(option):
72 continue
73
74 ret.append(Item(
75 desc = self.options[option]["desc"],
76 file = self.args["files"][option],
77 prio = self.options[option]["prio"],
78 type = option,
79 url = self.options[option]["url"] + self.args["files"][option],
80 ))
81
82 ret.sort(lambda a, b: cmp(a.prio, b.prio))
83 return ret
84
85 @property
86 def iso(self):
87 for download in self.downloads:
88 if download.type == "iso":
89 return download
90
91 @property
92 def torrent(self):
93 for download in self.downloads:
94 if download.type == "torrent":
95 return download
96
97 @property
98 def stable(self):
99 return self.status == "stable"
100
101 @property
102 def development(self):
103 return self.status == "development"
104
105
106class Releases(object):
107 def __init__(self, filename="releases.json"):
108 self.items = []
109
110 if filename:
111 self.load(filename)
112
113 def load(self, filename):
114 f = open(filename)
115 data = f.read()
116 f.close()
117
befc2e59 118 for item in json_loads(data):
8ccd2ff0 119 self.items.append(ReleaseItem(**_stringify(item)))
81675874 120
121 @property
122 def all(self):
123 return self.items
124
125 @property
126 def online(self):
127 ret = []
128 for item in self.all:
129 if item.online:
130 ret.append(item)
131 return ret
132
133 @property
134 def offline(self):
135 ret = []
136 for item in self.all:
137 if not item.online:
138 ret.append(item)
139 return ret
140
141 @property
142 def latest(self):
143 if self.stable:
144 return self.stable[0]
145
146 @property
147 def latest_devel(self):
148 if self.development:
149 return self.development[0]
150
151 @property
152 def stable(self):
153 ret = []
154 for item in self.online:
155 if item.stable:
156 ret.append(item)
157 return ret
158
159 @property
160 def development(self):
161 ret = []
162 for item in self.online:
163 if item.development:
164 ret.append(item)
165 return ret
166
167 @property
168 def torrents(self):
169 ret = []
170 for item in self.online:
171 if item.torrent:
172 ret.append(item)
173 return ret
174
175
176releases = Releases("releases.json")
177
178if __name__ == "__main__":
179 r = Releases()
180
181 print r.stable
182 print r.development
183 print r.latest
184 print r.online
185 print r.offline