]>
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_mirrors
import *
14 from .handlers_packages
import *
15 from .handlers_search
import *
16 from .handlers_updates
import *
17 from .handlers_users
import *
19 class IndexHandler(BaseHandler
):
21 jobs
= self
.pakfire
.jobs
.get_active()
22 jobs
+= self
.pakfire
.jobs
.get_latest(age
="24 hours", limit
=5)
27 for type in ("stable", "unstable", "testing"):
28 u
= self
.pakfire
.updates
.get_latest(type=type)
30 updates
.append((type, u
, active
))
33 self
.render("index.html", jobs
=jobs
, updates
=updates
)
36 class Error404Handler(BaseHandler
):
38 raise tornado
.web
.HTTPError(404)
41 class StatisticsMainHandler(BaseHandler
):
47 "builds_count" : self
.pakfire
.builds
.count(),
52 "jobs_count_all" : self
.pakfire
.jobs
.count(),
53 "jobs_avg_build_time" : self
.pakfire
.jobs
.get_average_build_time(),
56 self
.render("statistics/index.html", **args
)
59 class UploadsHandler(BaseHandler
):
60 @tornado.web
.authenticated
62 if not self
.current_user
.is_admin():
63 raise tornado
.web
.HTTPError(403)
65 self
.render("uploads-list.html", uploads
=self
.backend
.uploads
)
68 class DocsIndexHandler(BaseHandler
):
70 self
.render("docs-index.html")
73 class DocsBuildsHandler(BaseHandler
):
75 self
.render("docs-build.html")
78 class DocsUsersHandler(BaseHandler
):
80 self
.render("docs-users.html")
83 class DocsWhatsthisHandler(BaseHandler
):
85 self
.render("docs-whatsthis.html")
88 class FileDetailHandler(BaseHandler
):
90 pkg
, file = self
.pakfire
.packages
.get_with_file_by_uuid(uuid
)
93 raise tornado
.web
.HTTPError(404, "File not found")
95 self
.render("file-detail.html", pkg
=pkg
, file=file)
98 class LogHandler(BaseHandler
):
100 self
.render("log.html", log
=self
.pakfire
.log
)
103 class SessionsHandler(BaseHandler
):
105 # This is only accessible for administrators.
106 if not self
.current_user
.is_admin():
107 raise tornado
.web
.HTTPError(403)
109 @tornado.web
.authenticated
111 # Sort the sessions by user.
114 for s
in self
.backend
.sessions
:
116 users
[s
.user
].append(s
)
120 sessions
= sorted(users
.items())
122 self
.render("sessions/index.html", sessions
=sessions
)
125 class RepositoryDetailHandler(BaseHandler
):
126 def get(self
, distro
, repo
):
127 distro
= self
.pakfire
.distros
.get_by_name(distro
)
129 raise tornado
.web
.HTTPError(404)
131 repo
= distro
.get_repo(repo
)
133 raise tornado
.web
.HTTPError(404)
135 limit
= self
.get_argument("limit", 50)
141 offset
= self
.get_argument("offset", 0)
147 builds
= repo
.get_builds(limit
=limit
, offset
=offset
)
148 unpushed_builds
= repo
.get_unpushed_builds()
149 obsolete_builds
= repo
.get_obsolete_builds()
151 # Get the build times of this repository.
152 build_times
= repo
.get_build_times()
154 self
.render("repository-detail.html", distro
=distro
, repo
=repo
,
155 builds
=builds
, unpushed_builds
=unpushed_builds
,
156 obsolete_builds
=obsolete_builds
, build_times
=build_times
)
159 class RepositoryEditHandler(BaseHandler
):
160 @tornado.web
.authenticated
161 def get(self
, distro
, repo
):
162 distro
= self
.pakfire
.distros
.get_by_name(distro
)
164 raise tornado
.web
.HTTPError(404)
166 repo
= distro
.get_repo(repo
)
168 raise tornado
.web
.HTTPError(404)
170 # XXX check if user has permissions to do this
172 self
.render("repository-edit.html", distro
=distro
, repo
=repo
)
175 class RepositoryConfHandler(BaseHandler
):
176 def get(self
, distro
, repo
):
177 distro
= self
.pakfire
.distros
.get_by_name(distro
)
179 raise tornado
.web
.HTTPError(404)
181 repo
= distro
.get_repo(repo
)
183 raise tornado
.web
.HTTPError(404)
185 # This is a plaintext file.
186 self
.set_header("Content-Type", "text/plain")
189 self
.write("# Downloaded from the pakfire build service on %s.\n\n" \
190 % datetime
.datetime
.utcnow())
191 self
.write(repo
.get_conf())
195 class RepositoryMirrorlistHandler(BaseHandler
):
196 def get(self
, distro
, repo
):
197 distro
= self
.pakfire
.distros
.get_by_name(distro
)
199 raise tornado
.web
.HTTPError(404)
201 repo
= distro
.get_repo(repo
)
203 raise tornado
.web
.HTTPError(404)
205 # This is a plaintext file.
206 self
.set_header("Content-Type", "text/plain")
208 arch
= self
.get_argument("arch", None)
209 if not arch
or not self
.backend
.arches
.exists(arch
):
210 raise tornado
.web
.HTTPError(400, "You must specify a valid architecture")
213 "type" : "mirrorlist",
217 # A list with mirrors that are sent to the user.
220 # Only search for mirrors on repositories that are supposed to be found
224 # Select a list of preferred mirrors
225 for mirror
in self
.mirrors
.get_for_location(self
.current_address
):
227 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
228 "location" : mirror
.country_code
,
232 # Add all other mirrors at the end in a random order
233 remaining_mirrors
= [m
for m
in self
.backend
.mirrors
if not m
in mirrors
]
234 random
.shuffle(remaining_mirrors
)
236 for mirror
in remaining_mirrors
:
238 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
239 "location" : mirror
.country_code
,
244 repo_baseurl
= self
.pakfire
.settings
.get("repository_baseurl")
245 if repo_baseurl
.endswith("/"):
246 repo_baseurl
= repo_baseurl
[:-1]
248 for mirror
in self
.mirrors
.get_all():
249 print mirror
.url
, repo_baseurl
250 if not mirror
.url
== repo_baseurl
:
254 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
255 "location" : mirror
.country_code
,
259 mirrors
.append(mirror
)
262 ret
["mirrors"] = mirrors
267 class RepoActionHandler(BaseHandler
):
268 @tornado.web
.authenticated
269 def post(self
, type):
270 assert type in ("run", "remove")
272 action_id
= self
.get_argument("id")
274 action
= self
.pakfire
.repos
.get_action_by_id(action_id
)
276 raise tornado
.web
.HTTPError(400)
279 action
.run(self
.current_user
)
281 elif type == "remove":
282 action
.delete(self
.current_user
)