staticdir = $(datadir)/static
static_css_DATA = \
+ src/static/css/highlight.css \
src/static/css/site.css
static_cssdir = $(staticdir)/css
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
$(SASSC) --style compressed $< > $@
+src/static/css/highlight.css: Makefile
+ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
+ $(PYGMENTIZE) -S xcode -f html -a .highlight > $@
+
%.min.js: %.js
$(UGLIFYJS_PROCESS)
# Python
AM_PATH_PYTHON([3.9])
+# pygmentize (from pygments)
+AC_CHECK_PROG(PYGMENTIZE, [pygmentize], [pygmentize])
+if test -z "${PYGMENTIZE}"; then
+ AC_MSG_ERROR([pygmentize is required])
+fi
+
# SASSC
AC_CHECK_PROG(SASSC, [sassc], [sassc])
if test -z "${SASSC}"; then
AX_PYTHON_MODULE([boto3], [fatal])
AX_PYTHON_MODULE([location], [fatal])
+AX_PYTHON_MODULE([pygments], [fatal])
# ------------------------------------------------------------------------------
{% extends "../base.html" %}
-{% block title %}{{ _("View %(filename)s from %(pkg)s") % { "filename" : filename, "pkg" : pkg.friendly_name } }}{% end block %}
+{% block title %}{{ _("Package") }} - {{ package }} - {{ file }}{% end block %}
-{% block body %}
- <ul class="breadcrumb">
- <li>
- <a href="/">{{ _("Home") }}</a>
- <span class="divider">/</span>
- </li>
- <li>
- <a href="/packages">{{ _("Packages") }}</a>
- <span class="divider">/</span>
- </li>
- <li>
- <a href="/package/{{ pkg.name }}">{{ pkg.name }}</a>
- <span class="divider">/</span>
- </li>
- {% if pkg.build %}
+{% block container %}
+ <nav aria-label="{{ _("You are here:") }}" role="navigation">
+ <ul class="breadcrumbs">
<li>
- <a href="/build/{{ pkg.build.uuid }}">{{ pkg.friendly_version }}</a>
- <span class="divider">/</span>
+ <a href="/">{{ _("Home") }}</a>
</li>
- {% end %}
- {% if pkg.job %}
<li>
- <a href="/job/{{ pkg.job.uuid }}">{{ pkg.job.arch }}</a>
- <span class="divider">/</span>
+ <a href="/packages">{{ _("Packages") }}</a>
</li>
- {% end %}
- <li>
- <a href="/package/{{ pkg.uuid }}">{{ pkg.friendly_name }}</a>
- <span class="divider">/</span>
- </li>
- <li class="active">
- {{ _("View file") }}
- </li>
- </ul>
-
- <div class="page-header">
- <h2>
- {{ filename }}<br>
- <small><a href="/package/{{ pkg.uuid }}">{{ pkg.friendly_name }}</a> - {{ pkg.summary }}</small>
- </h2>
- </div>
+ <li>
+ <a href="/packages/{{ package.uuid }}">{{ package }}</a>
+ </li>
+ <li>
+ <span class="show-for-sr">{{ _("Current") }}: </span> {{ file.name }}
+ </li>
+ </ul>
+ </nav>
- <pre {% if not filesize >= 1024 ** 2 %}class="prettyprint linenums"{% end %}>{{ content }}</pre>
+ {% module Highlight(payload) %}
- <p class="muted ac">
- {{ _("Mimetype: %s") % mimetype }} - {{ _("Size: %s") % format_size(filesize) }} -
- <a href="/package/{{ pkg.uuid }}/download{{ filename }}">{{ _("Download file") }}</a>
- </p>
+ <a class="expanded primary button" href="/package/{{ package.uuid }}/download{{ file.name }}">
+ {{ _("Download (%s)") % format_size(file.size) }}
+ </a>
{% end block %}
template_path = TEMPLATESDIR,
static_path = STATICDIR,
ui_modules = {
+ "Highlight" : ui_modules.HighlightModule,
"Text" : ui_modules.TextModule,
"Modal" : ui_modules.ModalModule,
(r"/packages/([\w\-\+]+)", packages.NameHandler),
(r"/package/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/download(.*)",
packages.FileDownloadHandler),
- (r"/package/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/view(.*)", packages.PackageFileViewHandler),
+ (r"/package/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/view(.*)",
+ packages.FileViewHandler),
(r"/package/([\w\-\+]+)/properties", packages.PackagePropertiesHandler),
# Files
self.finish(payload)
-class PackageFileViewHandler(FileDownloadHandler):
- def get(self, pkg_uuid, filename):
- pkg, f, mimetype = self.get_file(pkg_uuid, filename)
+class FileViewHandler(base.BaseHandler):
+ async def get(self, uuid, path):
+ package = self.backend.packages.get_by_uuid(uuid)
+ if not package:
+ raise tornado.web.HTTPError(404, "Could not find package: %s" % uuid)
- # Read in the data.
- content = f.read()
- f.close()
+ # Fetch the file
+ file = package.get_file(path)
+ if not file:
+ raise tornado.web.HTTPError(404, "Could not find file %s in %s" % (path, package))
+
+ # Is this file viewable?
+ if not file.is_viewable():
+ raise tornado.web.HTTPError(400, "%s cannot be viewed" % file)
# These pages should not be indexed
self.add_header("X-Robots-Tag", "noindex")
- self.render("packages/view-file.html", pkg=pkg, filename=filename,
- mimetype=mimetype, content=content, filesize=f.size)
+ # Fetch payload
+ payload = await file.get_payload()
+
+ self.render("packages/view-file.html", package=package, file=file, payload=payload)
class DependenciesModule(ui_modules.UIModule):
#!/usr/bin/python
-
-
import datetime
import math
+import pygments
+import pygments.formatters
+import pygments.lexers
import pytz
import re
import tornado.web
return self.LINK % ("http://cve.mitre.org/cgi-bin/cvename.cgi?name=%s" % m.group(1), m.group(0))
+class HighlightModule(UIModule):
+ def render(self, text):
+ # Find a lexer
+ try:
+ lexer = pygments.lexers.guess_lexer(text)
+ except pygments.util.ClassNotFound as e:
+ lexer = pygments.lexers.special.TextLexer()
+
+ # Find a formatter
+ formatter = pygments.formatters.HtmlFormatter(linenos="table")
+
+ return pygments.highlight(text, lexer, formatter)
+
+ def css_files(self):
+ return (
+ "css/highlight.css",
+ )
+
+
class CommitMessageModule(UIModule):
def render(self, commit):
return self.render_string("modules/commit-message.html", commit=commit)