]> git.ipfire.org Git - pbs.git/blame - src/web/handlers.py
Rename web/handlers_distro.py -> web/distributions.py
[pbs.git] / src / web / handlers.py
CommitLineData
9137135a
MT
1#!/usr/bin/python
2
c660ff59 3import random
9137135a
MT
4import tornado.web
5
0919f216
MT
6from . import base
7
2c909128
MT
8from .handlers_jobs import *
9from .handlers_keys import *
2c909128
MT
10from .handlers_packages import *
11from .handlers_search import *
12from .handlers_updates import *
13from .handlers_users import *
9137135a 14
0919f216 15class IndexHandler(base.BaseHandler):
9137135a 16 def get(self):
6e63ed49 17 jobs = self.pakfire.jobs.get_active()
9779008c 18 jobs += self.pakfire.jobs.get_latest(age="24 hours", limit=5)
9137135a 19
f6e6ff79
MT
20 # Updates
21 updates = []
22 active = True
23 for type in ("stable", "unstable", "testing"):
24 u = self.pakfire.updates.get_latest(type=type)
25 if u:
26 updates.append((type, u, active))
27 active = False
9137135a 28
6e63ed49 29 self.render("index.html", jobs=jobs, updates=updates)
9137135a 30
9137135a 31
0919f216 32class UploadsHandler(base.BaseHandler):
9137135a 33 @tornado.web.authenticated
9137135a 34 def get(self):
f6e6ff79
MT
35 if not self.current_user.is_admin():
36 raise tornado.web.HTTPError(403)
9137135a 37
2f64fe68 38 self.render("uploads-list.html", uploads=self.backend.uploads)
9137135a
MT
39
40
0919f216 41class DocsIndexHandler(base.BaseHandler):
9137135a
MT
42 def get(self):
43 self.render("docs-index.html")
44
45
0919f216 46class DocsBuildsHandler(base.BaseHandler):
9137135a
MT
47 def get(self):
48 self.render("docs-build.html")
49
50
0919f216 51class DocsUsersHandler(base.BaseHandler):
9137135a
MT
52 def get(self):
53 self.render("docs-users.html")
54
55
0919f216 56class DocsWhatsthisHandler(base.BaseHandler):
9137135a 57 def get(self):
f6e6ff79 58 self.render("docs-whatsthis.html")
9137135a
MT
59
60
0919f216 61class FileDetailHandler(base.BaseHandler):
9137135a
MT
62 def get(self, uuid):
63 pkg, file = self.pakfire.packages.get_with_file_by_uuid(uuid)
64
65 if not file:
66 raise tornado.web.HTTPError(404, "File not found")
67
68 self.render("file-detail.html", pkg=pkg, file=file)
69
70
0919f216 71class LogHandler(base.BaseHandler):
9137135a 72 def get(self):
f6e6ff79 73 self.render("log.html", log=self.pakfire.log)
9137135a
MT
74
75
0919f216 76class SessionsHandler(base.BaseHandler):
20d7f5eb
MT
77 def prepare(self):
78 # This is only accessible for administrators.
79 if not self.current_user.is_admin():
80 raise tornado.web.HTTPError(403)
81
82 @tornado.web.authenticated
83 def get(self):
20d7f5eb
MT
84 # Sort the sessions by user.
85 users = {}
86
b6295831 87 for s in self.backend.sessions:
b0315eb4 88 print s.user, s.user in users
20d7f5eb
MT
89 try:
90 users[s.user].append(s)
91 except KeyError:
92 users[s.user] = [s]
93
94 sessions = sorted(users.items())
95
96 self.render("sessions/index.html", sessions=sessions)
97
98
0919f216 99class RepositoryDetailHandler(base.BaseHandler):
f6e6ff79
MT
100 def get(self, distro, repo):
101 distro = self.pakfire.distros.get_by_name(distro)
9137135a 102 if not distro:
f6e6ff79 103 raise tornado.web.HTTPError(404)
9137135a 104
f6e6ff79
MT
105 repo = distro.get_repo(repo)
106 if not repo:
107 raise tornado.web.HTTPError(404)
9137135a 108
f6e6ff79
MT
109 limit = self.get_argument("limit", 50)
110 try:
111 limit = int(limit)
112 except ValueError:
113 limit = None
9137135a 114
f6e6ff79
MT
115 offset = self.get_argument("offset", 0)
116 try:
117 offset = int(offset)
118 except ValueError:
119 offset = None
9137135a 120
f6e6ff79
MT
121 builds = repo.get_builds(limit=limit, offset=offset)
122 unpushed_builds = repo.get_unpushed_builds()
123 obsolete_builds = repo.get_obsolete_builds()
124
125 # Get the build times of this repository.
126 build_times = repo.get_build_times()
127
128 self.render("repository-detail.html", distro=distro, repo=repo,
129 builds=builds, unpushed_builds=unpushed_builds,
130 obsolete_builds=obsolete_builds, build_times=build_times)
9137135a 131
9137135a 132
0919f216 133class RepositoryEditHandler(base.BaseHandler):
9137135a 134 @tornado.web.authenticated
f6e6ff79
MT
135 def get(self, distro, repo):
136 distro = self.pakfire.distros.get_by_name(distro)
9137135a 137 if not distro:
f6e6ff79 138 raise tornado.web.HTTPError(404)
9137135a 139
f6e6ff79
MT
140 repo = distro.get_repo(repo)
141 if not repo:
142 raise tornado.web.HTTPError(404)
9137135a 143
f6e6ff79 144 # XXX check if user has permissions to do this
9137135a 145
f6e6ff79 146 self.render("repository-edit.html", distro=distro, repo=repo)
9137135a
MT
147
148
0919f216 149class RepositoryConfHandler(base.BaseHandler):
f6e6ff79
MT
150 def get(self, distro, repo):
151 distro = self.pakfire.distros.get_by_name(distro)
152 if not distro:
153 raise tornado.web.HTTPError(404)
9137135a 154
f6e6ff79
MT
155 repo = distro.get_repo(repo)
156 if not repo:
157 raise tornado.web.HTTPError(404)
9137135a 158
f6e6ff79
MT
159 # This is a plaintext file.
160 self.set_header("Content-Type", "text/plain")
161
162 # Write the header.
163 self.write("# Downloaded from the pakfire build service on %s.\n\n" \
164 % datetime.datetime.utcnow())
165 self.write(repo.get_conf())
166 self.finish()
167
168
0919f216 169class RepositoryMirrorlistHandler(base.BaseHandler):
9137135a
MT
170 def get(self, distro, repo):
171 distro = self.pakfire.distros.get_by_name(distro)
172 if not distro:
173 raise tornado.web.HTTPError(404)
174
175 repo = distro.get_repo(repo)
176 if not repo:
177 raise tornado.web.HTTPError(404)
178
30a2a19c
MT
179 # Send nothing if repository isn't supposed to be mirrored
180 if not repo.mirrored:
181 raise tornado.web.HTTPError(404)
182
f6e6ff79
MT
183 # This is a plaintext file.
184 self.set_header("Content-Type", "text/plain")
185
186 arch = self.get_argument("arch", None)
087a5f09
MT
187 if not arch or not self.backend.arches.exists(arch):
188 raise tornado.web.HTTPError(400, "You must specify a valid architecture")
f6e6ff79
MT
189
190 ret = {
191 "type" : "mirrorlist",
192 "version" : 1,
193 }
194
f6e6ff79 195 mirrors = []
085b9151 196 for mirror in self.backend.mirrors.make_mirrorlist(self.current_address):
30a2a19c 197 mirrors.append({
5a9456d5 198 "url" : "/".join((mirror.url, repo.basepath, arch)),
30a2a19c 199 "location" : mirror.country_code,
30a2a19c 200 })
f6e6ff79 201
139603a7
MT
202 # Always use the buildservice itself as last resort
203 mirrors.append({
204 "url" : repo.url,
205 })
206
f6e6ff79 207 ret["mirrors"] = mirrors
30a2a19c 208 self.finish(ret)
9137135a
MT
209
210
0919f216 211class RepoActionHandler(base.BaseHandler):
9137135a
MT
212 @tornado.web.authenticated
213 def post(self, type):
214 assert type in ("run", "remove")
215
216 action_id = self.get_argument("id")
217
218 action = self.pakfire.repos.get_action_by_id(action_id)
219 if not action:
220 raise tornado.web.HTTPError(400)
221
222 if type == "run":
223 action.run(self.current_user)
224
225 elif type == "remove":
226 action.delete(self.current_user)