]>
git.ipfire.org Git - pbs.git/blob - src/web/handlers.py
7 class IndexHandler(base
.BaseHandler
):
12 jobs
+= self
.backend
.jobs
.get_active()
14 # Get some recently finished jobs
15 jobs
+= self
.backend
.jobs
.get_recently_ended(limit
=12)
20 for type in ("stable", "unstable", "testing"):
21 u
= self
.backend
.updates
.get_latest(type=type)
23 updates
.append((type, u
, active
))
26 self
.render("index.html", jobs
=jobs
, updates
=updates
)
29 class UploadsHandler(base
.BaseHandler
):
30 @tornado.web
.authenticated
32 if not self
.current_user
.is_admin():
33 raise tornado
.web
.HTTPError(403)
35 self
.render("uploads-list.html", uploads
=self
.backend
.uploads
)
38 class DocsIndexHandler(base
.BaseHandler
):
40 self
.render("docs-index.html")
43 class DocsBuildsHandler(base
.BaseHandler
):
45 self
.render("docs-build.html")
48 class DocsUsersHandler(base
.BaseHandler
):
50 self
.render("docs-users.html")
53 class DocsWhatsthisHandler(base
.BaseHandler
):
55 self
.render("docs-whatsthis.html")
58 class FileDetailHandler(base
.BaseHandler
):
60 pkg
, file = self
.backend
.packages
.get_with_file_by_uuid(uuid
)
63 raise tornado
.web
.HTTPError(404, "File not found")
65 self
.render("file-detail.html", pkg
=pkg
, file=file)
68 class LogHandler(base
.BaseHandler
):
70 self
.render("log.html", log
=self
.backend
.log
)
73 class SessionsHandler(base
.BaseHandler
):
75 # This is only accessible for administrators.
76 if not self
.current_user
.is_admin():
77 raise tornado
.web
.HTTPError(403)
79 @tornado.web
.authenticated
81 # Sort the sessions by user.
84 for s
in self
.backend
.sessions
:
85 print s
.user
, s
.user
in users
87 users
[s
.user
].append(s
)
91 sessions
= sorted(users
.items())
93 self
.render("sessions/index.html", sessions
=sessions
)
96 class RepositoryDetailHandler(base
.BaseHandler
):
97 def get(self
, distro
, repo
):
98 distro
= self
.backend
.distros
.get_by_name(distro
)
100 raise tornado
.web
.HTTPError(404)
102 repo
= distro
.get_repo(repo
)
104 raise tornado
.web
.HTTPError(404)
106 limit
= self
.get_argument("limit", 50)
112 offset
= self
.get_argument("offset", 0)
118 builds
= repo
.get_builds(limit
=limit
, offset
=offset
)
119 unpushed_builds
= repo
.get_unpushed_builds()
120 obsolete_builds
= repo
.get_obsolete_builds()
122 # Get the build times of this repository.
123 build_times
= repo
.get_build_times()
125 self
.render("repository-detail.html", distro
=distro
, repo
=repo
,
126 builds
=builds
, unpushed_builds
=unpushed_builds
,
127 obsolete_builds
=obsolete_builds
, build_times
=build_times
)
130 class RepositoryEditHandler(base
.BaseHandler
):
131 @tornado.web
.authenticated
132 def get(self
, distro
, repo
):
133 distro
= self
.backend
.distros
.get_by_name(distro
)
135 raise tornado
.web
.HTTPError(404)
137 repo
= distro
.get_repo(repo
)
139 raise tornado
.web
.HTTPError(404)
141 # XXX check if user has permissions to do this
143 self
.render("repository-edit.html", distro
=distro
, repo
=repo
)
146 class RepositoryConfHandler(base
.BaseHandler
):
147 def get(self
, distro
, repo
):
148 distro
= self
.backend
.distros
.get_by_name(distro
)
150 raise tornado
.web
.HTTPError(404)
152 repo
= distro
.get_repo(repo
)
154 raise tornado
.web
.HTTPError(404)
156 # This is a plaintext file.
157 self
.set_header("Content-Type", "text/plain")
160 self
.write("# Downloaded from the pakfire build service on %s.\n\n" \
161 % datetime
.datetime
.utcnow())
162 self
.write(repo
.get_conf())
166 class RepositoryMirrorlistHandler(base
.BaseHandler
):
167 def get(self
, distro
, repo
):
168 distro
= self
.backend
.distros
.get_by_name(distro
)
170 raise tornado
.web
.HTTPError(404)
172 repo
= distro
.get_repo(repo
)
174 raise tornado
.web
.HTTPError(404)
176 # Send nothing if repository isn't supposed to be mirrored
177 if not repo
.mirrored
:
178 raise tornado
.web
.HTTPError(404)
180 # This is a plaintext file.
181 self
.set_header("Content-Type", "text/plain")
183 arch
= self
.get_argument("arch", None)
184 if not arch
or not self
.backend
.arches
.exists(arch
):
185 raise tornado
.web
.HTTPError(400, "You must specify a valid architecture")
188 "type" : "mirrorlist",
193 for mirror
in self
.backend
.mirrors
.make_mirrorlist(self
.current_address
):
195 "url" : "/".join((mirror
.url
, repo
.basepath
, arch
)),
196 "location" : mirror
.country_code
,
199 # Always use the buildservice itself as last resort
201 "url" : "/".join((repo
.url
, arch
)),
204 ret
["mirrors"] = mirrors
208 class RepoActionHandler(base
.BaseHandler
):
209 @tornado.web
.authenticated
210 def post(self
, type):
211 assert type in ("run", "remove")
213 action_id
= self
.get_argument("id")
215 action
= self
.backend
.repos
.get_action_by_id(action_id
)
217 raise tornado
.web
.HTTPError(400)
220 action
.run(self
.current_user
)
222 elif type == "remove":
223 action
.delete(self
.current_user
)