9 from ..constants
import BUFFER_SIZE
11 class IndexHandler(base
.BaseHandler
):
13 # Sort all packages in an array like "<first char>" --> [packages, ...]
14 # to print them in a table for each letter of the alphabet.
17 for pkg
in self
.backend
.packages
.get_list():
18 c
= pkg
.name
[0].lower()
21 packages
[c
].append(pkg
)
25 self
.render("packages/index.html", packages
=packages
)
28 class PackageIDDetailHandler(base
.BaseHandler
):
30 package
= self
.packages
.get_by_id(id)
32 return tornado
.web
.HTTPError(404, "Package not found: %s" % id)
34 self
.render("package-detail.html", package
=package
)
37 class PackageNameHandler(base
.BaseHandler
):
39 builds
= self
.backend
.builds
.get_active_builds(name
)
41 raise tornado
.web
.HTTPError(404, "Package '%s' was not found" % name
)
43 # Get the latest build to show the package meta information.
44 latest_build
= builds
[0]
46 # Get the latest bugs from bugzilla.
47 bugs
= self
.backend
.bugzilla
.get_bugs_from_component(name
)
49 self
.render("package-detail-list.html", name
=name
, builds
=builds
,
50 latest_build
=latest_build
, pkg
=latest_build
.pkg
, bugs
=bugs
)
53 class PackageScratchBuildsHandler(base
.BaseHandler
):
55 offset
= self
.get_argument("offset", 0)
56 limit
= self
.get_argument("limit", 10)
58 scratch_builds
= self
.backend
.builds
.get_by_name(name
, type="scratch",
59 limit
=limit
, offset
=offset
)
62 latest_build
= scratch_builds
[0]
64 release_builds
= self
.backend
.builds
.get_by_name(name
, type="release", limit
=1)
65 if not release_builds
:
66 raise tornado
.web
.HTTPError(404, "Could not find any build with this name: %s" % name
)
68 latest_build
= release_builds
[0]
70 self
.render("packages/builds/scratch.html", builds
=scratch_builds
,
74 class PackageChangelogHandler(base
.BaseHandler
):
76 limit
= self
.get_argument("limit", 10)
83 offset
= self
.get_argument("offset", 0)
89 # Get one more build than requested to find out if there are more items
90 # to display (next button).
91 builds
= self
.backend
.builds
.get_changelog(name
, limit
=limit
+ 1, offset
=offset
)
93 if len(builds
) >= limit
:
103 # Clip list to limit.
104 builds
= builds
[:limit
]
106 self
.render("packages/changelog.html", name
=name
, builds
=builds
,
107 limit
=limit
, offset
=offset
, have_prev
=have_prev
, have_next
=have_next
)
110 class PackageDetailHandler(base
.BaseHandler
):
112 pkg
= self
.backend
.packages
.get_by_uuid(uuid
)
114 raise tornado
.web
.HTTPError(404, "Package not found: %s" % uuid
)
116 self
.render("package-detail.html", pkg
=pkg
)
118 @tornado.web
.authenticated
119 def post(self
, name
, epoch
, version
, release
):
120 pkg
= self
.backend
.packages
.get_by_tuple(name
, epoch
, version
, release
)
122 action
= self
.get_argument("action", None)
124 if action
== "comment":
125 pkg
.comment(self
.current_user
.id, self
.get_argument("text"),
126 self
.get_argument("vote", None) or "none")
128 self
.render("package-detail.html", pkg
=pkg
)
131 class PackagePropertiesHandler(base
.BaseHandler
):
132 @tornado.web
.authenticated
134 build
= self
.backend
.builds
.get_latest_by_name(name
)
137 raise tornado
.web
.HTTPError(404, "Package '%s' was not found" % name
)
139 # Check if the user has sufficient permissions.
140 if not build
.has_perm(self
.current_user
):
141 raise tornado
.web
.HTTPError(403, "User %s is not allowed to manage build %s" \
142 % (self
.current_user
, build
))
144 self
.render("package-properties.html", build
=build
,
145 pkg
=build
.pkg
, properties
=build
.pkg
.properties
)
147 @tornado.web
.authenticated
148 def post(self
, name
):
149 build
= self
.backend
.builds
.get_latest_by_name(name
)
152 raise tornado
.web
.HTTPError(404, "Package '%s' was not found" % name
)
154 # Check if the user has sufficient permissions.
155 if not build
.has_perm(self
.current_user
):
156 raise tornado
.web
.HTTPError(403, "User %s is not allowed to manage build %s" \
157 % (self
.current_user
, build
))
159 critical_path
= self
.get_argument("critical_path", False)
163 critical_path
= False
164 build
.pkg
.update_property("critical_path", critical_path
)
167 class PackageFileDownloadHandler(base
.BaseHandler
):
168 def get_file(self
, pkg_uuid
, filename
):
170 pkg
= self
.backend
.packages
.get_by_uuid(pkg_uuid
)
172 raise tornado
.web
.HTTPError(404, "Package not found: %s" % pkg_uuid
)
174 # Check if the package has got a file with the given name.
175 file = pkg
.get_file(filename
)
177 raise tornado
.web
.HTTPError(404, "Package %s does not contain file %s" % (pkg
, filename
))
179 # Open the package in the filesystem.
180 pkg_file
= pkg
.open()
182 raise tornado
.web
.HTTPError(404, "Could not open package %s" % pkg
.path
)
184 # Open the file to transfer it to the client.
185 f
= pkg_file
.open_file(filename
)
187 raise tornado
.web
.HTTPError(404, "Package %s does not contain file %s" % (pkg_file
, filename
))
189 # Guess the MIME type of the file.
190 (type, encoding
) = mimetypes
.guess_type(filename
)
194 return (pkg
, f
, type)
196 def get(self
, pkg_uuid
, filename
):
197 pkg
, f
, mimetype
= self
.get_file(pkg_uuid
, filename
)
199 # Send the filename and mimetype in header.
200 self
.set_header("Content-Disposition", "attachment; filename=%s" % os
.path
.basename(filename
))
201 self
.set_header("Content-Type", mimetype
)
203 # These pages should not be indexed
204 self
.add_header("X-Robots-Tag", "noindex")
206 # Transfer the content chunk by chunk.
208 buf
= f
.read(BUFFER_SIZE
)
220 class PackageFileViewHandler(PackageFileDownloadHandler
):
221 def get(self
, pkg_uuid
, filename
):
222 pkg
, f
, mimetype
= self
.get_file(pkg_uuid
, filename
)
228 # These pages should not be indexed
229 self
.add_header("X-Robots-Tag", "noindex")
231 self
.render("packages/view-file.html", pkg
=pkg
, filename
=filename
,
232 mimetype
=mimetype
, content
=content
, filesize
=f
.size
)
235 class PackageBuildsTimesHandler(base
.BaseHandler
):
237 latest_build
= self
.backend
.builds
.get_latest_by_name(name
)
239 # If no build with this name was found, we cannot go on.
241 raise tornado
.web
.HTTPError(404)
243 # Get the summary stats.
244 build_times_summary
= self
.backend
.builds
.get_build_times_summary(name
)
246 self
.render("packages/builds/times.html", pkg
=latest_build
.pkg
,
247 build_times_summary
=build_times_summary
)