]> git.ipfire.org Git - pbs.git/blob - src/web/handlers_distro.py
8b8148779e3030c25afbfc22f83e797e5fe9a0f5
[pbs.git] / src / web / handlers_distro.py
1 #!/usr/bin/python
2
3 from .handlers_base import *
4
5 class DistributionListHandler(BaseHandler):
6 def get(self):
7 self.render("distro-list.html", distros=self.backend.distros)
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.backend.arches, 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 # Check if arch exists
58 if not self.backend.arches.exists(arch):
59 continue
60
61 arches.append(arch)
62
63 distro.arches = arches
64
65 self.redirect("/distribution/%s" % distro.sname)
66
67
68 class DistroSourceDetailHandler(BaseHandler):
69 def get(self, distro_ident, source_ident):
70 distro = self.pakfire.distros.get_by_name(distro_ident)
71 if not distro:
72 raise tornado.web.HTTPError(404, "Distro not found")
73
74 source = distro.get_source(source_ident)
75 if not source:
76 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
77 % (source_ident, distro.name))
78
79 # Get the latest commits.
80 commits = source.get_commits(limit=5)
81
82 self.render("distro-source-detail.html", distro=distro, source=source,
83 commits=commits)
84
85
86 class DistroSourceCommitsHandler(BaseHandler):
87 def get(self, distro_ident, source_ident):
88 distro = self.pakfire.distros.get_by_name(distro_ident)
89 if not distro:
90 raise tornado.web.HTTPError(404, "Distro not found")
91
92 source = distro.get_source(source_ident)
93 if not source:
94 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
95 % (source_ident, distro.name))
96
97 offset = self.get_argument("offset", 0)
98 try:
99 offset = int(offset)
100 except ValueError:
101 offset = 0
102
103 limit = self.get_argument("limit", 50)
104 try:
105 limit = int(limit)
106 except ValueError:
107 limit = 50
108
109 commits = source.get_commits(limit=limit, offset=offset)
110
111 self.render("distro-source-commits.html", distro=distro, source=source,
112 commits=commits, limit=limit, offset=offset, number=50)
113
114
115 class DistroSourceCommitDetailHandler(BaseHandler):
116 def get(self, distro_ident, source_ident, commit_ident):
117 distro = self.pakfire.distros.get_by_name(distro_ident)
118 if not distro:
119 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
120
121 source = distro.get_source(source_ident)
122 if not source:
123 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
124 % (source_ident, distro.name))
125
126 commit = source.get_commit(commit_ident)
127 if not commit:
128 raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \
129 % (commit_ident, source.name))
130
131 self.render("distro-source-commit-detail.html", distro=distro,
132 source=source, commit=commit)
133
134
135 class DistroSourceCommitResetHandler(BaseHandler):
136 @tornado.web.authenticated
137 def get(self, distro_ident, source_ident, commit_ident):
138 distro = self.pakfire.distros.get_by_name(distro_ident)
139 if not distro:
140 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
141
142 source = distro.get_source(source_ident)
143 if not source:
144 raise tornado.web.HTTPError(404, "Source '%s' not found in distro '%s'" \
145 % (source_ident, distro.name))
146
147 commit = source.get_commit(commit_ident)
148 if not commit:
149 raise tornado.web.HTTPError(404, "Commit '%s' not found in source '%s'" \
150 % (commit_ident, source.name))
151
152 if not self.current_user.is_admin():
153 raise tornado.web.HTTPError(403)
154
155 confirmed = self.get_argument("confirmed", None)
156 if confirmed:
157 commit.reset()
158
159 self.redirect("/distro/%s/source/%s/%s" % \
160 (distro.identifier, source.identifier, commit.revision))
161 return
162
163 self.render("distro-source-commit-reset.html", distro=distro,
164 source=source, commit=commit)
165
166
167 class DistroUpdateCreateHandler(BaseHandler):
168 def get(self, distro_ident):
169 distro = self.pakfire.distros.get_by_name(distro_ident)
170 if not distro:
171 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
172
173 # Get all preset builds.
174 builds = []
175 for build in self.get_arguments("builds", []):
176 build = self.pakfire.builds.get_by_uuid(build)
177 builds.append(build)
178
179 builds.sort()
180
181 self.render("distro-update-edit.html", update=None,
182 distro=distro, builds=builds)
183
184
185 class DistroUpdateDetailHandler(BaseHandler):
186 def get(self, distro_ident, year, num):
187 distro = self.pakfire.distros.get_by_name(distro_ident)
188 if not distro:
189 raise tornado.web.HTTPError(404, "Distribution '%s' not found" % distro_ident)
190
191 update = distro.get_update(year, num)
192 if not update:
193 raise tornado.web.HTTPError(404, "Update cannot be found: %s %s" % (year, num))
194
195 self.render("distro-update-detail.html", distro=distro,
196 update=update, repo=update.repo, user=update.user)
197
198 # XXX currently unused
199 class SourceListHandler(BaseHandler):
200 def get(self):
201 sources = self.pakfire.sources.get_all()
202
203 self.render("source-list.html", sources=sources)
204
205
206 class SourceDetailHandler(BaseHandler):
207 def get(self, id):
208 source = self.pakfire.sources.get_by_id(id)
209
210 self.render("source-detail.html", source=source)