summaryrefslogtreecommitdiff
path: root/webapp.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2013-07-27 09:32:03 +0200
committerHelmut Grohne <helmut@subdivi.de>2013-07-27 09:32:03 +0200
commit0c27c95a9c55b82b2c7e5e90b885c87578e895d0 (patch)
treef7b501e59dc15764a84ef9758f5b597e497719cf /webapp.py
parent03e7e27b440917081369e797e09de975912cb68c (diff)
downloaddebian-dedup-0c27c95a9c55b82b2c7e5e90b885c87578e895d0.tar.gz
move templates to dedup package
They cluttered webapp.py and now vim can give proper highlighting for the templates.
Diffstat (limited to 'webapp.py')
-rwxr-xr-xwebapp.py146
1 files changed, 6 insertions, 140 deletions
diff --git a/webapp.py b/webapp.py
index c080d41..e180087 100755
--- a/webapp.py
+++ b/webapp.py
@@ -20,7 +20,7 @@ hash_functions = [
("sha512", "gzip_sha512"),
("gzip_sha512", "sha512")]
-jinjaenv = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
+jinjaenv = jinja2.Environment(loader=jinja2.PackageLoader("dedup", "templates"))
def format_size(size):
size = float(size)
@@ -45,145 +45,11 @@ def function_combination(function1, function2):
jinjaenv.filters["filesizeformat"] = format_size
base_template = jinjaenv.get_template("base.html")
-
-package_template = jinjaenv.from_string(
-"""{% extends "base.html" %}
-{% block title %}duplication of {{ package|e }}{% endblock %}
-{% block content %}<h1>{{ package|e }}</h1>
-<p>Version: {{ version|e }}</p>
-<p>Architecture: {{ architecture|e }}</p>
-<p>Number of files: {{ num_files }}</p>
-<p>Total size: {{ total_size|filesizeformat }}</p>
-{%- if shared -%}
- {%- for function, sharing in shared.items() -%}
- <h3>sharing with respect to {{ function|e }}</h3>
- <table border='1'><tr><th>package</th><th>files shared</th><th>data shared</th></tr>
- {%- for entry in sharing|sort(attribute="savable", reverse=true) -%}
- <tr><td{% if not entry.package or entry.package in dependencies %} class="dependency"{% endif %}>
- {%- if entry.package %}<a href="{{ entry.package|e }}"><span class="binary-package">{{ entry.package|e }}</span></a>{% else %}self{% endif %}
- <a href="../compare/{{ package|e }}/{{ entry.package|default(package, true)|e }}">compare</a></td>
- <td>{{ entry.duplicate }} ({{ (100 * entry.duplicate / num_files)|int }}%)</td>
- <td>{{ entry.savable|filesizeformat }} ({{ (100 * entry.savable / total_size)|int }}%)</td></tr>
- {%- endfor -%}
- </table>
- {%- endfor -%}
-<p>Note: Packages with yellow background are required to be installed when this package is installed.</p>
-{%- endif -%}
-{%- if issues -%}
- <h3>issues with particular files</h3>
- <table border='1'><tr><th>filename</th><th>issue</th></tr>
- {%- for filename, issue in issues|dictsort(true) -%}
- <tr><td><span class="filename">{{ filename|e }}</span></td><td>{{ issue|e }}</td></tr>
- {%- endfor -%}
- </table>
-{%- endif -%}
-{% endblock %}""")
-
-detail_template = jinjaenv.from_string(
-"""{% extends "base.html" %}
-{% block title %}sharing between {{ details1.package|e }} and {{ details2.package|e }}{% endblock%}
-{% block content %}
-<h1><a href="../../binary/{{ details1.package|e }}">{{ details1.package|e }}</a> &lt;-&gt; <a href="../../binary/{{ details2.package|e }}">{{ details2.package|e }}</a></h1>
-<p>Version of {{ details1.package|e }}: {{ details1.version|e }}</p>
-<p>Architecture of {{ details1.package|e }}: {{ details1.architecture|e }}</p>
-{%- if details1.package != details2.package -%}
-<p>Version of {{ details2.package|e }}: {{ details2.version|e }}</p>
-<p>Architecture of {{ details2.package|e }}: {{ details2.architecture|e }}</p>
-{%- endif -%}
-<table border='1'><tr><th colspan="2">{{ details1.package|e }}</th><th colspan="2">{{ details2.package|e }}</th></tr>
-<tr><th>size</th><th>filename</th><th>hash functions</th><th>filename</th></tr>
-{%- for entry in shared -%}
- <tr><td{% if entry.matches|length > 1 %} rowspan={{ entry.matches|length }}{% endif %}>{{ entry.size|filesizeformat }}</td><td{% if entry.matches|length > 1 %} rowspan={{ entry.matches|length }}{% endif %}>
- {%- for filename in entry.filenames %}<span class="filename">{{ filename|e }}</span>{% endfor -%}</td><td>
- {% for filename, match in entry.matches.items() -%}
- {% if not loop.first %}<tr><td>{% endif -%}
- {%- for funccomb, hashvalue in match.items() -%}
- <a href="../../hash/{{ funccomb[0]|e }}/{{ hashvalue|e }}">{{ funccomb[0]|e }}</a>
- {%- if funccomb[0] != funccomb[1] %} -&gt; <a href="../../hash/{{ funccomb[1]|e }}/{{ hashvalue|e }}">{{ funccomb[1]|e }}</a>{% endif %}
- {%- if not loop.last %}, {% endif %}
- {%- endfor -%}
- </td><td><span class="filename">{{ filename|e }}</span></td></tr>
- {%- endfor -%}
-{%- endfor -%}
-</table>
-{% endblock %}""")
-
-hash_template = jinjaenv.from_string(
-"""{% extends "base.html" %}
-{% block title %}information on {{ function|e }} hash {{ hashvalue|e }}{% endblock %}
-{% block content %}
-<h1>{{ function|e }} {{ hashvalue|e }}</h1>
-<table border='1'><tr><th>package</th><th>filename</th><th>size</th><th>different function</th></tr>
-{%- for entry in entries -%}
- <tr><td><a href="../../binary/{{ entry.package|e }}"><span class="binary-package">{{ entry.package|e }}</span></a></td>
- <td><span class="filename">{{ entry.filename|e }}</span></td><td>{{ entry.size|filesizeformat }}</td>
- <td>{% if function != entry.function %}{{ entry.function|e }}{% endif %}</td></tr>
-{%- endfor -%}
-</table>
-{% endblock %}""")
-
-index_template = jinjaenv.from_string(
-"""{% extends "base.html" %}
-{% block title %}Debian duplication detector{% endblock %}
-{% block header %}
- <script type="text/javascript">
- function getLinkTarget() {
- var pkg = document.getElementById("pkg_name").value;
- if(pkg) {
- return "/binary/"+pkg;
- }
- return '#';
- }
- function processData() {
- var link = document.getElementById("perma_link");
- link.href = getLinkTarget();
- link.text = location.href + getLinkTarget();
- }
- window.onload = function() {
- document.getElementById('pkg_name').onkeyup = processData;
- document.getElementById("pkg_form").onsubmit = function () {
- location.href = getLinkTarget();
- return false;
- }
- processData();
- document.getElementById("form_div").style.display = '';
- }
- </script>
-{% endblock %}
-{% block content %}
-<h1>Debian duplication detector</h1>
-<ul>
-<li>To inspect a particlar binary package, go to <pre>binary/&lt;packagename&gt;</pre> Example: <a href="binary/git">binary/git</a>
- <div style="display:none" id="form_div"><fieldset>
- <legend>Inspect package</legend>
- <noscript><b>This form is disfunctional when javascript is not enabled</b></noscript>
- Enter binary package to inspect - Note: Non-existing packages will result in <b>404</b>-Errors
- <form id="pkg_form">
- <label for="pkg_name">Name: </label><input type="text" size="30" name="pkg_name" id="pkg_name">
- <input type="submit" value="Go"> Permanent Link: <a id="perma_link" href="#"></a>
- </form>
- </fieldset></div></li>
-<li>To inspect a combination of binary packages go to <pre>compare/&lt;firstpackage&gt;/&lt;secondpackage&gt;</pre> Example: <a href="compare/git/git">compare/git/git</a></li>
-<li>To discover package shipping a particular file go to <pre>hash/sha512/&lt;hashvalue&gt;</pre> Example: <a href="hash/sha512/7633623b66b5e686bb94dd96a7cdb5a7e5ee00e87004fab416a5610d59c62badaf512a2e26e34e2455b7ed6b76690d2cd47464836d7d85d78b51d50f7e933d5c">hash/sha512/7633623b66b5e686bb94dd96a7cdb5a7e5ee00e87004fab416a5610d59c62badaf512a2e26e34e2455b7ed6b76690d2cd47464836d7d85d78b51d50f7e933d5c</a></li>
-</ul>
-{% endblock %}""")
-
-source_template = jinjaenv.from_string(
-"""{% extends "base.html" %}
-{% block title %}overview of {{ source|e }}{% endblock %}
-{% block content %}
-<h1>overview of {{ source|e }}</h1>
-<table border='1'><tr><th>binary from {{ source|e }}</th><th>savable</th><th>other package</th></tr>
-{% for package, sharing in packages.items() %}
- <tr><td><a href="../binary/{{ package|e }}"><span class="binary-package">{{ package|e }}</span></a></td><td>
- {%- if sharing -%}
- {{ sharing.savable|filesizeformat }}</td><td><a href="../binary/{{ sharing.package|e }}"><span class="binary-package">{{ sharing.package|e }}</span></a> <a href="../compare/{{ package|e }}/{{ sharing.package|e }}">compare</a>
- {%- else -%}</td><td>{%- endif -%}
- </td></tr>
-{% endfor %}
-</table>
-<p>Note: Not all sharing listed here. Click on binary packages with non-zero savable to see more.</p>
-{% endblock %}""")
+package_template = jinjaenv.get_template("binary.html")
+detail_template = jinjaenv.get_template("compare.html")
+hash_template = jinjaenv.get_template("hash.html")
+index_template = jinjaenv.get_template("index.html")
+source_template = jinjaenv.get_template("source.html")
def encode_and_buffer(iterator):
buff = b""