]> git.ipfire.org Git - people/jschlag/pbs.git/blob - src/web/handlers_distro.py
Use autotools
[people/jschlag/pbs.git] / src / web / handlers_distro.py
1 #!/usr/bin/python
2
3 from handlers_base import *
4
5
6 class DistributionListHandler(BaseHandler):
7 def get(self):
8 distros = self.pakfire.distros.get_all()
9
10 self.render("distro-list.html", distros=distros)
11
12
13 class DistributionDetailHandler(BaseHandler):
14 def get(self, name):
15 distro = self.pakfire.distros.get_by_name(name)
16 if not distro:
17 raise tornado.web.HTTPError(404, "Distro not found")
18
19 self.render("distro-detail.html", distro=distro)
20
21
22 class DistributionEditHandler(BaseHandler):
23 def prepare(self):
24 self.sources = self.pakfire.sources.get_all()
25
26 @tornado.web.authenticated
27 def get(self, name):
28 distro = self.pakfire.distros.get_by_name(name)
29 if not distro:
30 raise tornado.web.HTTPError(404, "Distro not found")
31
32 self.render("distro-edit.html", distro=distro,
33 arches=self.arches.get_all(), sources=self.sources)
34
35 @tornado.web.authenticated
36 def post(self, name):
37 distro = self.pakfire.distros.get_by_name(name)
38 if not distro:
39 raise tornado.web.HTTPError(404, "Distro not found")
40
41 name = self.get_argument("name", distro.name)
42 vendor = self.get_argument("vendor", distro.vendor)
43 contact = self.get_argument("contact", "")
44 slogan = self.get_argument("slogan", distro.slogan)
45 tag = self.get_argument("tag", "")
46
47 distro.set("name", name)
48 distro.set("vendor", vendor)
49 distro.set("slogan", slogan)
50
51 # Update the contact email address.
52 distro.contact = contact
53
54 # Update the tag.
55 distro.tag = tag
56
57 # Update architectures.
58 arches = []
59 for arch in self.get_arguments("arches", []):
60 try:
61 arch_id = int(arch)
62 except ValueError:
63 continue
64
65 if not self.arches.exists(arch_id):
66 continue
67
68 arch = self.arches.get_by_id(arch_id)
69 arches.append(arch)
70
71 distro.arches = arches
72
73 self.redirect("/distribution/%s" % distro.sname)
74
75
76 class DistroSourceDetailHandler(BaseHandler):
77 def get(self, distro_ident, source_ident):
78 distro = self.pakfire.distros.get_by_name(distro_ident)
79 if not distro:
80 raise tornado.web.HTTPError(404, "Distro not found")
81
82 source = distro.get_source(source_ident)
83 if not source:
84 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
85 % (source_ident, distro.name))
86
87 # Get the latest commits.
88 commits = source.get_commits(limit=5)
89
90 self.render("distro-source-detail.html", distro=distro, source=source,
91 commits=commits)
92
93
94 class DistroSourceCommitsHandler(BaseHandler):
95 def get(self, distro_ident, source_ident):
96 distro = self.pakfire.distros.get_by_name(distro_ident)
97 if not distro:
98 raise tornado.web.HTTPError(404, "Distro not found")
99
100 source = distro.get_source(source_ident)
101 if not source:
102 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
103 % (source_ident, distro.name))
104
105 offset = self.get_argument("offset", 0)
106 try:
107 offset = int(offset)
108 except ValueError:
109 offset = 0
110
111 limit = self.get_argument("limit", 50)
112 try:
113 limit = int(limit)
114 except ValueError:
115 limit = 50
116
117 commits = source.get_commits(limit=limit, offset=offset)
118
119 self.render("distro-source-commits.html", distro=distro, source=source,
120 commits=commits, limit=limit, offset=offset, number=50)
121
122
123 class DistroSourceCommitDetailHandler(BaseHandler):
124 def get(self, distro_ident, source_ident, commit_ident):
125 distro = self.pakfire.distros.get_by_name(distro_ident)
126 if not distro:
127 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
128
129 source = distro.get_source(source_ident)
130 if not source:
131 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
132 % (source_ident, distro.name))
133
134 commit = source.get_commit(commit_ident)
135 if not commit:
136 raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \
137 % (commit_ident, source.name))
138
139 self.render("distro-source-commit-detail.html", distro=distro,
140 source=source, commit=commit)
141
142
143 class DistroSourceCommitResetHandler(BaseHandler):
144 @tornado.web.authenticated
145 def get(self, distro_ident, source_ident, commit_ident):
146 distro = self.pakfire.distros.get_by_name(distro_ident)
147 if not distro:
148 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
149
150 source = distro.get_source(source_ident)
151 if not source:
152 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
153 % (source_ident, distro.name))
154
155 commit = source.get_commit(commit_ident)
156 if not commit:
157 raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \
158 % (commit_ident, source.name))
159
160 if not self.current_user.is_admin():
161 raise tornado.web.HTTPError(403)
162
163 confirmed = self.get_argument("confirmed", None)
164 if confirmed:
165 commit.reset()
166
167 self.redirect("/distro/%s/source/%s/%s" % \
168 (distro.identifier, source.identifier, commit.revision))
169 return
170
171 self.render("distro-source-commit-reset.html", distro=distro,
172 source=source, commit=commit)
173
174
175 class DistroUpdateCreateHandler(BaseHandler):
176 def get(self, distro_ident):
177 distro = self.pakfire.distros.get_by_name(distro_ident)
178 if not distro:
179 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
180
181 # Get all preset builds.
182 builds = []
183 for build in self.get_arguments("builds", []):
184 build = self.pakfire.builds.get_by_uuid(build)
185 builds.append(build)
186
187 builds.sort()
188
189 self.render("distro-update-edit.html", update=None,
190 distro=distro, builds=builds)
191
192
193 class DistroUpdateDetailHandler(BaseHandler):
194 def get(self, distro_ident, year, num):
195 distro = self.pakfire.distros.get_by_name(distro_ident)
196 if not distro:
197 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
198
199 update = distro.get_update(year, num)
200 if not update:
201 raise tornado.web.HTTPError(404, "Update cannot be found: %s %s" % (year, num))
202
203 self.render("distro-update-detail.html", distro=distro,
204 update=update, repo=update.repo, user=update.user)
205
206 # XXX currently unused
207 class SourceListHandler(BaseHandler):
208 def get(self):
209 sources = self.pakfire.sources.get_all()
210
211 self.render("source-list.html", sources=sources)
212
213
214 class SourceDetailHandler(BaseHandler):
215 def get(self, id):
216 source = self.pakfire.sources.get_by_id(id)
217
218 self.render("source-detail.html", source=source)