]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/web/handlers.py
5 from handlers_auth
import *
6 from handlers_base
import *
7 from handlers_builds
import *
8 from handlers_builders
import *
9 from handlers_distro
import *
10 from handlers_jobs
import *
11 from handlers_keys
import *
12 from handlers_mirrors
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_next()
22 jobs
+= self
.pakfire
.jobs
.get_latest(age
="24 HOUR", 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 uploads
= self
.pakfire
.uploads
.get_all()
67 self
.render("uploads-list.html", uploads
=uploads
)
70 class DocsIndexHandler(BaseHandler
):
72 self
.render("docs-index.html")
75 class DocsBuildsHandler(BaseHandler
):
77 self
.render("docs-build.html")
80 class DocsUsersHandler(BaseHandler
):
82 self
.render("docs-users.html")
85 class DocsWhatsthisHandler(BaseHandler
):
87 self
.render("docs-whatsthis.html")
90 class FileDetailHandler(BaseHandler
):
92 pkg
, file = self
.pakfire
.packages
.get_with_file_by_uuid(uuid
)
95 raise tornado
.web
.HTTPError(404, "File not found")
97 self
.render("file-detail.html", pkg
=pkg
, file=file)
100 class LogHandler(BaseHandler
):
102 self
.render("log.html", log
=self
.pakfire
.log
)
105 class SessionsHandler(BaseHandler
):
107 # This is only accessible for administrators.
108 if not self
.current_user
.is_admin():
109 raise tornado
.web
.HTTPError(403)
111 @tornado.web
.authenticated
113 sessions
= self
.pakfire
.sessions
.get_all()
115 # Sort the sessions by user.
120 users
[s
.user
].append(s
)
124 sessions
= sorted(users
.items())
126 self
.render("sessions/index.html", sessions
=sessions
)
129 class RepositoryDetailHandler(BaseHandler
):
130 def get(self
, distro
, repo
):
131 distro
= self
.pakfire
.distros
.get_by_name(distro
)
133 raise tornado
.web
.HTTPError(404)
135 repo
= distro
.get_repo(repo
)
137 raise tornado
.web
.HTTPError(404)
139 limit
= self
.get_argument("limit", 50)
145 offset
= self
.get_argument("offset", 0)
151 builds
= repo
.get_builds(limit
=limit
, offset
=offset
)
152 unpushed_builds
= repo
.get_unpushed_builds()
153 obsolete_builds
= repo
.get_obsolete_builds()
155 # Get the build times of this repository.
156 build_times
= repo
.get_build_times()
158 self
.render("repository-detail.html", distro
=distro
, repo
=repo
,
159 builds
=builds
, unpushed_builds
=unpushed_builds
,
160 obsolete_builds
=obsolete_builds
, build_times
=build_times
)
163 class RepositoryEditHandler(BaseHandler
):
164 @tornado.web
.authenticated
165 def get(self
, distro
, repo
):
166 distro
= self
.pakfire
.distros
.get_by_name(distro
)
168 raise tornado
.web
.HTTPError(404)
170 repo
= distro
.get_repo(repo
)
172 raise tornado
.web
.HTTPError(404)
174 # XXX check if user has permissions to do this
176 self
.render("repository-edit.html", distro
=distro
, repo
=repo
)
179 class RepositoryConfHandler(BaseHandler
):
180 def get(self
, distro
, repo
):
181 distro
= self
.pakfire
.distros
.get_by_name(distro
)
183 raise tornado
.web
.HTTPError(404)
185 repo
= distro
.get_repo(repo
)
187 raise tornado
.web
.HTTPError(404)
189 # This is a plaintext file.
190 self
.set_header("Content-Type", "text/plain")
193 self
.write("# Downloaded from the pakfire build service on %s.\n\n" \
194 % datetime
.datetime
.utcnow())
195 self
.write(repo
.get_conf())
199 class RepositoryMirrorlistHandler(BaseHandler
):
200 def get(self
, distro
, repo
):
201 distro
= self
.pakfire
.distros
.get_by_name(distro
)
203 raise tornado
.web
.HTTPError(404)
205 repo
= distro
.get_repo(repo
)
207 raise tornado
.web
.HTTPError(404)
209 # This is a plaintext file.
210 self
.set_header("Content-Type", "text/plain")
212 arch
= self
.get_argument("arch", None)
213 arch
= self
.pakfire
.arches
.get_by_name(arch
)
216 raise tornado
.web
.HTTPError(400, "You must specify the architecture.")
219 "type" : "mirrorlist",
223 # A list with mirrors that are sent to the user.
226 # Only search for mirrors on repositories that are supposed to be found
230 # See how many mirrors we can max. find.
231 num_mirrors
= self
.mirrors
.count(status
="enabled")
232 assert num_mirrors
> 0
234 # Create a list with all mirrors that is up to 50 mirrors long.
235 # First add all preferred mirrors and then fill the rest up
236 # with other mirrors.
237 if num_mirrors
>= 10:
240 MAX_MIRRORS
= num_mirrors
243 for mirror
in self
.mirrors
.get_for_location(self
.remote_address
):
245 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
.name
)),
246 "location" : mirror
.country_code
,
250 while MAX_MIRRORS
- len(mirrors
) > 0:
251 mirror
= self
.mirrors
.get_random(limit
=1)[0]
254 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
.name
)),
255 "location" : mirror
.country_code
,
259 if not mirror
in mirrors
:
260 mirrors
.append(mirror
)
263 repo_baseurl
= self
.pakfire
.settings
.get("repository_baseurl")
264 if repo_baseurl
.endswith("/"):
265 repo_baseurl
= repo_baseurl
[:-1]
267 for mirror
in self
.mirrors
.get_all():
268 print mirror
.url
, repo_baseurl
269 if not mirror
.url
== repo_baseurl
:
273 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
.name
)),
274 "location" : mirror
.country_code
,
278 mirrors
.append(mirror
)
281 ret
["mirrors"] = mirrors
286 class RepoActionHandler(BaseHandler
):
287 @tornado.web
.authenticated
288 def post(self
, type):
289 assert type in ("run", "remove")
291 action_id
= self
.get_argument("id")
293 action
= self
.pakfire
.repos
.get_action_by_id(action_id
)
295 raise tornado
.web
.HTTPError(400)
298 action
.run(self
.current_user
)
300 elif type == "remove":
301 action
.delete(self
.current_user
)