]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/web/handlers.py
e83a82eaeac4a9ab1eac7aff2f0d64a8c7f7922e
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 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 # Sort the sessions by user.
116 for s
in self
.backend
.sessions
:
118 users
[s
.user
].append(s
)
122 sessions
= sorted(users
.items())
124 self
.render("sessions/index.html", sessions
=sessions
)
127 class RepositoryDetailHandler(BaseHandler
):
128 def get(self
, distro
, repo
):
129 distro
= self
.pakfire
.distros
.get_by_name(distro
)
131 raise tornado
.web
.HTTPError(404)
133 repo
= distro
.get_repo(repo
)
135 raise tornado
.web
.HTTPError(404)
137 limit
= self
.get_argument("limit", 50)
143 offset
= self
.get_argument("offset", 0)
149 builds
= repo
.get_builds(limit
=limit
, offset
=offset
)
150 unpushed_builds
= repo
.get_unpushed_builds()
151 obsolete_builds
= repo
.get_obsolete_builds()
153 # Get the build times of this repository.
154 build_times
= repo
.get_build_times()
156 self
.render("repository-detail.html", distro
=distro
, repo
=repo
,
157 builds
=builds
, unpushed_builds
=unpushed_builds
,
158 obsolete_builds
=obsolete_builds
, build_times
=build_times
)
161 class RepositoryEditHandler(BaseHandler
):
162 @tornado.web
.authenticated
163 def get(self
, distro
, repo
):
164 distro
= self
.pakfire
.distros
.get_by_name(distro
)
166 raise tornado
.web
.HTTPError(404)
168 repo
= distro
.get_repo(repo
)
170 raise tornado
.web
.HTTPError(404)
172 # XXX check if user has permissions to do this
174 self
.render("repository-edit.html", distro
=distro
, repo
=repo
)
177 class RepositoryConfHandler(BaseHandler
):
178 def get(self
, distro
, repo
):
179 distro
= self
.pakfire
.distros
.get_by_name(distro
)
181 raise tornado
.web
.HTTPError(404)
183 repo
= distro
.get_repo(repo
)
185 raise tornado
.web
.HTTPError(404)
187 # This is a plaintext file.
188 self
.set_header("Content-Type", "text/plain")
191 self
.write("# Downloaded from the pakfire build service on %s.\n\n" \
192 % datetime
.datetime
.utcnow())
193 self
.write(repo
.get_conf())
197 class RepositoryMirrorlistHandler(BaseHandler
):
198 def get(self
, distro
, repo
):
199 distro
= self
.pakfire
.distros
.get_by_name(distro
)
201 raise tornado
.web
.HTTPError(404)
203 repo
= distro
.get_repo(repo
)
205 raise tornado
.web
.HTTPError(404)
207 # This is a plaintext file.
208 self
.set_header("Content-Type", "text/plain")
210 arch
= self
.get_argument("arch", None)
211 if not arch
or not self
.backend
.arches
.exists(arch
):
212 raise tornado
.web
.HTTPError(400, "You must specify a valid architecture")
215 "type" : "mirrorlist",
219 # A list with mirrors that are sent to the user.
222 # Only search for mirrors on repositories that are supposed to be found
226 # Select a list of preferred mirrors
227 for mirror
in self
.mirrors
.get_for_location(self
.current_address
):
229 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
230 "location" : mirror
.country_code
,
234 # Add all other mirrors at the end in a random order
235 remaining_mirrors
= [m
for m
in self
.backend
.mirrors
if not m
in mirrors
]
236 random
.shuffle(remaining_mirrors
)
238 for mirror
in remaining_mirrors
:
240 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
241 "location" : mirror
.country_code
,
246 repo_baseurl
= self
.pakfire
.settings
.get("repository_baseurl")
247 if repo_baseurl
.endswith("/"):
248 repo_baseurl
= repo_baseurl
[:-1]
250 for mirror
in self
.mirrors
.get_all():
251 print mirror
.url
, repo_baseurl
252 if not mirror
.url
== repo_baseurl
:
256 "url" : "/".join((mirror
.url
, distro
.identifier
, repo
.identifier
, arch
)),
257 "location" : mirror
.country_code
,
261 mirrors
.append(mirror
)
264 ret
["mirrors"] = mirrors
269 class RepoActionHandler(BaseHandler
):
270 @tornado.web
.authenticated
271 def post(self
, type):
272 assert type in ("run", "remove")
274 action_id
= self
.get_argument("id")
276 action
= self
.pakfire
.repos
.get_action_by_id(action_id
)
278 raise tornado
.web
.HTTPError(400)
281 action
.run(self
.current_user
)
283 elif type == "remove":
284 action
.delete(self
.current_user
)