]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/web/handlers.py
6 from .handlers_auth
import *
7 from .handlers_base
import *
8 from .handlers_builds
import *
9 from .handlers_builders
import *
10 from .handlers_distro
import *
11 from .handlers_jobs
import *
12 from .handlers_keys
import *
13 from .handlers_packages
import *
14 from .handlers_search
import *
15 from .handlers_updates
import *
16 from .handlers_users
import *
18 class IndexHandler(BaseHandler
):
20 jobs
= self
.pakfire
.jobs
.get_active()
21 jobs
+= self
.pakfire
.jobs
.get_latest(age
="24 hours", limit
=5)
26 for type in ("stable", "unstable", "testing"):
27 u
= self
.pakfire
.updates
.get_latest(type=type)
29 updates
.append((type, u
, active
))
32 self
.render("index.html", jobs
=jobs
, updates
=updates
)
35 class Error404Handler(BaseHandler
):
37 raise tornado
.web
.HTTPError(404)
40 class StatisticsMainHandler(BaseHandler
):
46 "builds_count" : self
.pakfire
.builds
.count(),
51 "jobs_count_all" : self
.pakfire
.jobs
.count(),
52 "jobs_avg_build_time" : self
.pakfire
.jobs
.get_average_build_time(),
55 self
.render("statistics/index.html", **args
)
58 class UploadsHandler(BaseHandler
):
59 @tornado.web
.authenticated
61 if not self
.current_user
.is_admin():
62 raise tornado
.web
.HTTPError(403)
64 self
.render("uploads-list.html", uploads
=self
.backend
.uploads
)
67 class DocsIndexHandler(BaseHandler
):
69 self
.render("docs-index.html")
72 class DocsBuildsHandler(BaseHandler
):
74 self
.render("docs-build.html")
77 class DocsUsersHandler(BaseHandler
):
79 self
.render("docs-users.html")
82 class DocsWhatsthisHandler(BaseHandler
):
84 self
.render("docs-whatsthis.html")
87 class FileDetailHandler(BaseHandler
):
89 pkg
, file = self
.pakfire
.packages
.get_with_file_by_uuid(uuid
)
92 raise tornado
.web
.HTTPError(404, "File not found")
94 self
.render("file-detail.html", pkg
=pkg
, file=file)
97 class LogHandler(BaseHandler
):
99 self
.render("log.html", log
=self
.pakfire
.log
)
102 class SessionsHandler(BaseHandler
):
104 # This is only accessible for administrators.
105 if not self
.current_user
.is_admin():
106 raise tornado
.web
.HTTPError(403)
108 @tornado.web
.authenticated
110 # Sort the sessions by user.
113 for s
in self
.backend
.sessions
:
115 users
[s
.user
].append(s
)
119 sessions
= sorted(users
.items())
121 self
.render("sessions/index.html", sessions
=sessions
)
124 class RepositoryDetailHandler(BaseHandler
):
125 def get(self
, distro
, repo
):
126 distro
= self
.pakfire
.distros
.get_by_name(distro
)
128 raise tornado
.web
.HTTPError(404)
130 repo
= distro
.get_repo(repo
)
132 raise tornado
.web
.HTTPError(404)
134 limit
= self
.get_argument("limit", 50)
140 offset
= self
.get_argument("offset", 0)
146 builds
= repo
.get_builds(limit
=limit
, offset
=offset
)
147 unpushed_builds
= repo
.get_unpushed_builds()
148 obsolete_builds
= repo
.get_obsolete_builds()
150 # Get the build times of this repository.
151 build_times
= repo
.get_build_times()
153 self
.render("repository-detail.html", distro
=distro
, repo
=repo
,
154 builds
=builds
, unpushed_builds
=unpushed_builds
,
155 obsolete_builds
=obsolete_builds
, build_times
=build_times
)
158 class RepositoryEditHandler(BaseHandler
):
159 @tornado.web
.authenticated
160 def get(self
, distro
, repo
):
161 distro
= self
.pakfire
.distros
.get_by_name(distro
)
163 raise tornado
.web
.HTTPError(404)
165 repo
= distro
.get_repo(repo
)
167 raise tornado
.web
.HTTPError(404)
169 # XXX check if user has permissions to do this
171 self
.render("repository-edit.html", distro
=distro
, repo
=repo
)
174 class RepositoryConfHandler(BaseHandler
):
175 def get(self
, distro
, repo
):
176 distro
= self
.pakfire
.distros
.get_by_name(distro
)
178 raise tornado
.web
.HTTPError(404)
180 repo
= distro
.get_repo(repo
)
182 raise tornado
.web
.HTTPError(404)
184 # This is a plaintext file.
185 self
.set_header("Content-Type", "text/plain")
188 self
.write("# Downloaded from the pakfire build service on %s.\n\n" \
189 % datetime
.datetime
.utcnow())
190 self
.write(repo
.get_conf())
194 class RepositoryMirrorlistHandler(BaseHandler
):
195 def get(self
, distro
, repo
):
196 distro
= self
.pakfire
.distros
.get_by_name(distro
)
198 raise tornado
.web
.HTTPError(404)
200 repo
= distro
.get_repo(repo
)
202 raise tornado
.web
.HTTPError(404)
204 # Send nothing if repository isn't supposed to be mirrored
205 if not repo
.mirrored
:
206 raise tornado
.web
.HTTPError(404)
208 # This is a plaintext file.
209 self
.set_header("Content-Type", "text/plain")
211 arch
= self
.get_argument("arch", None)
212 if not arch
or not self
.backend
.arches
.exists(arch
):
213 raise tornado
.web
.HTTPError(400, "You must specify a valid architecture")
216 "type" : "mirrorlist",
220 # A list with mirrors that are sent to the user.
223 # Select a list of preferred mirrors
224 for mirror
in self
.mirrors
.get_for_location(self
.current_address
):
226 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
227 "location" : mirror
.country_code
,
231 # Add all other mirrors at the end in a random order
232 remaining_mirrors
= [m
for m
in self
.backend
.mirrors
if not m
in mirrors
]
233 random
.shuffle(remaining_mirrors
)
235 for mirror
in remaining_mirrors
:
237 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
238 "location" : mirror
.country_code
,
242 ret
["mirrors"] = mirrors
246 class RepoActionHandler(BaseHandler
):
247 @tornado.web
.authenticated
248 def post(self
, type):
249 assert type in ("run", "remove")
251 action_id
= self
.get_argument("id")
253 action
= self
.pakfire
.repos
.get_action_by_id(action_id
)
255 raise tornado
.web
.HTTPError(400)
258 action
.run(self
.current_user
)
260 elif type == "remove":
261 action
.delete(self
.current_user
)