]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
2c909128 | 3 | from .handlers_base import * |
f6e6ff79 MT |
4 | |
5 | class DistributionListHandler(BaseHandler): | |
6 | def get(self): | |
e459cbba | 7 | self.render("distro-list.html", distros=self.backend.distros) |
f6e6ff79 MT |
8 | |
9 | ||
10 | class DistributionDetailHandler(BaseHandler): | |
11 | def get(self, name): | |
12 | distro = self.pakfire.distros.get_by_name(name) | |
13 | if not distro: | |
14 | raise tornado.web.HTTPError(404, "Distro not found") | |
15 | ||
16 | self.render("distro-detail.html", distro=distro) | |
17 | ||
18 | ||
19 | class DistributionEditHandler(BaseHandler): | |
20 | def prepare(self): | |
21 | self.sources = self.pakfire.sources.get_all() | |
22 | ||
23 | @tornado.web.authenticated | |
24 | def get(self, name): | |
25 | distro = self.pakfire.distros.get_by_name(name) | |
26 | if not distro: | |
27 | raise tornado.web.HTTPError(404, "Distro not found") | |
28 | ||
29 | self.render("distro-edit.html", distro=distro, | |
30 | arches=self.arches.get_all(), sources=self.sources) | |
31 | ||
32 | @tornado.web.authenticated | |
33 | def post(self, name): | |
34 | distro = self.pakfire.distros.get_by_name(name) | |
35 | if not distro: | |
36 | raise tornado.web.HTTPError(404, "Distro not found") | |
37 | ||
38 | name = self.get_argument("name", distro.name) | |
39 | vendor = self.get_argument("vendor", distro.vendor) | |
40 | contact = self.get_argument("contact", "") | |
41 | slogan = self.get_argument("slogan", distro.slogan) | |
42 | tag = self.get_argument("tag", "") | |
43 | ||
44 | distro.set("name", name) | |
45 | distro.set("vendor", vendor) | |
46 | distro.set("slogan", slogan) | |
47 | ||
48 | # Update the contact email address. | |
49 | distro.contact = contact | |
50 | ||
51 | # Update the tag. | |
52 | distro.tag = tag | |
53 | ||
54 | # Update architectures. | |
55 | arches = [] | |
56 | for arch in self.get_arguments("arches", []): | |
57 | try: | |
58 | arch_id = int(arch) | |
59 | except ValueError: | |
60 | continue | |
61 | ||
62 | if not self.arches.exists(arch_id): | |
63 | continue | |
64 | ||
65 | arch = self.arches.get_by_id(arch_id) | |
66 | arches.append(arch) | |
67 | ||
68 | distro.arches = arches | |
69 | ||
70 | self.redirect("/distribution/%s" % distro.sname) | |
71 | ||
72 | ||
73 | class DistroSourceDetailHandler(BaseHandler): | |
74 | def get(self, distro_ident, source_ident): | |
75 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
76 | if not distro: | |
77 | raise tornado.web.HTTPError(404, "Distro not found") | |
78 | ||
79 | source = distro.get_source(source_ident) | |
80 | if not source: | |
81 | raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \ | |
82 | % (source_ident, distro.name)) | |
83 | ||
84 | # Get the latest commits. | |
85 | commits = source.get_commits(limit=5) | |
86 | ||
87 | self.render("distro-source-detail.html", distro=distro, source=source, | |
88 | commits=commits) | |
89 | ||
90 | ||
91 | class DistroSourceCommitsHandler(BaseHandler): | |
92 | def get(self, distro_ident, source_ident): | |
93 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
94 | if not distro: | |
95 | raise tornado.web.HTTPError(404, "Distro not found") | |
96 | ||
97 | source = distro.get_source(source_ident) | |
98 | if not source: | |
99 | raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \ | |
100 | % (source_ident, distro.name)) | |
101 | ||
102 | offset = self.get_argument("offset", 0) | |
103 | try: | |
104 | offset = int(offset) | |
105 | except ValueError: | |
106 | offset = 0 | |
107 | ||
108 | limit = self.get_argument("limit", 50) | |
109 | try: | |
110 | limit = int(limit) | |
111 | except ValueError: | |
112 | limit = 50 | |
113 | ||
114 | commits = source.get_commits(limit=limit, offset=offset) | |
115 | ||
116 | self.render("distro-source-commits.html", distro=distro, source=source, | |
117 | commits=commits, limit=limit, offset=offset, number=50) | |
118 | ||
119 | ||
120 | class DistroSourceCommitDetailHandler(BaseHandler): | |
121 | def get(self, distro_ident, source_ident, commit_ident): | |
122 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
123 | if not distro: | |
124 | raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident) | |
125 | ||
126 | source = distro.get_source(source_ident) | |
127 | if not source: | |
128 | raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \ | |
129 | % (source_ident, distro.name)) | |
130 | ||
131 | commit = source.get_commit(commit_ident) | |
132 | if not commit: | |
133 | raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \ | |
134 | % (commit_ident, source.name)) | |
135 | ||
136 | self.render("distro-source-commit-detail.html", distro=distro, | |
137 | source=source, commit=commit) | |
138 | ||
139 | ||
140 | class DistroSourceCommitResetHandler(BaseHandler): | |
141 | @tornado.web.authenticated | |
142 | def get(self, distro_ident, source_ident, commit_ident): | |
143 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
144 | if not distro: | |
145 | raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident) | |
146 | ||
147 | source = distro.get_source(source_ident) | |
148 | if not source: | |
149 | raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \ | |
150 | % (source_ident, distro.name)) | |
151 | ||
152 | commit = source.get_commit(commit_ident) | |
153 | if not commit: | |
154 | raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \ | |
155 | % (commit_ident, source.name)) | |
156 | ||
157 | if not self.current_user.is_admin(): | |
158 | raise tornado.web.HTTPError(403) | |
159 | ||
160 | confirmed = self.get_argument("confirmed", None) | |
161 | if confirmed: | |
162 | commit.reset() | |
163 | ||
164 | self.redirect("/distro/%s/source/%s/%s" % \ | |
165 | (distro.identifier, source.identifier, commit.revision)) | |
166 | return | |
167 | ||
168 | self.render("distro-source-commit-reset.html", distro=distro, | |
169 | source=source, commit=commit) | |
170 | ||
171 | ||
172 | class DistroUpdateCreateHandler(BaseHandler): | |
173 | def get(self, distro_ident): | |
174 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
175 | if not distro: | |
176 | raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident) | |
177 | ||
178 | # Get all preset builds. | |
179 | builds = [] | |
180 | for build in self.get_arguments("builds", []): | |
181 | build = self.pakfire.builds.get_by_uuid(build) | |
182 | builds.append(build) | |
183 | ||
184 | builds.sort() | |
185 | ||
186 | self.render("distro-update-edit.html", update=None, | |
187 | distro=distro, builds=builds) | |
188 | ||
189 | ||
190 | class DistroUpdateDetailHandler(BaseHandler): | |
191 | def get(self, distro_ident, year, num): | |
192 | distro = self.pakfire.distros.get_by_name(distro_ident) | |
193 | if not distro: | |
194 | raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident) | |
195 | ||
196 | update = distro.get_update(year, num) | |
197 | if not update: | |
198 | raise tornado.web.HTTPError(404, "Update cannot be found: %s %s" % (year, num)) | |
199 | ||
200 | self.render("distro-update-detail.html", distro=distro, | |
201 | update=update, repo=update.repo, user=update.user) | |
202 | ||
203 | # XXX currently unused | |
204 | class SourceListHandler(BaseHandler): | |
205 | def get(self): | |
206 | sources = self.pakfire.sources.get_all() | |
207 | ||
208 | self.render("source-list.html", sources=sources) | |
209 | ||
210 | ||
211 | class SourceDetailHandler(BaseHandler): | |
212 | def get(self, id): | |
213 | source = self.pakfire.sources.get_by_id(id) | |
214 | ||
215 | self.render("source-detail.html", source=source) |