From 4a35c7d54a9c45c185e45c7ec8b74cbaa34f63f3 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 5 Mar 2013 08:39:06 +0100 Subject: webapp: added /source/ page --- webapp.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/webapp.py b/webapp.py index 893a31d..6c06e28 100755 --- a/webapp.py +++ b/webapp.py @@ -145,6 +145,22 @@ index_template = jinjaenv.from_string( {% endblock %}""") +source_template = jinjaenv.from_string( +"""{% extends "base.html" %} +{% block title %}overview of {{ source|e }}{% endblock %} +{% block content %} +

overview of {{ source|e }}

+ +{% for package, sharing in packages.items() %} + +{% endfor %} +
binary from {{ source|e }}savableother package
{{ package|e }} + {%- if sharing -%} + {{ sharing.savable|format_size }}{{ sharing.package|e }} compare + {%- else -%}{%- endif -%} +
+{% endblock %}""") + def encode_and_buffer(iterator): buff = b"" for elem in iterator: @@ -190,6 +206,7 @@ class Application(object): Rule("/binary/", methods=("GET",), endpoint="package"), Rule("/compare//", methods=("GET",), endpoint="detail"), Rule("/hash//", methods=("GET",), endpoint="hash"), + Rule("/source/", methods=("GET",), endpoint="source"), ]) @Request.application @@ -207,6 +224,8 @@ class Application(object): if not request.environ["PATH_INFO"]: raise RequestRedirect(request.environ["SCRIPT_NAME"] + "/") return html_response(index_template.stream()) + elif endpoint == "source": + return self.show_source(args["package"]) raise NotFound() except HTTPException as e: return e @@ -313,6 +332,25 @@ class Application(object): params = dict(function=function, hashvalue=hashvalue, entries=entries) return html_response(hash_template.render(params)) + def show_source(self, package): + cur = self.db.cursor() + cur.execute("SELECT package FROM source WHERE source = ?;", + (package,)) + binpkgs = dict.fromkeys(pkg for pkg, in fetchiter(cur)) + if not binpkgs: + raise NotFound + cur.execute("SELECT source.package, sharing.package2, sharing.func1, sharing.func2, sharing.files, sharing.size FROM source JOIN sharing ON source.package = sharing.package1 WHERE source.source = ?;", + (package,)) + for binary, otherbin, func1, func2, files, size in fetchiter(cur): + entry = dict(package=otherbin, + funccomb=function_combination(func1, func2), + duplicate=files, savable=size) + oldentry = binpkgs.get(binary) + if not (oldentry and oldentry["savable"] >= size): + binpkgs[binary] = entry + params = dict(source=package, packages=binpkgs) + return html_response(source_template.render(params)) + def main(): app = Application(sqlite3.connect("test.sqlite3")) #app = DebuggedApplication(app, evalex=True) -- cgit v1.2.3