move templates to dedup package
authorHelmut Grohne <helmut@subdivi.de>
Sat, 27 Jul 2013 07:32:03 +0000 (09:32 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Sat, 27 Jul 2013 07:32:03 +0000 (09:32 +0200)
They cluttered webapp.py and now vim can give proper highlighting for
the templates.

README
base.html [deleted file]
dedup/templates/base.html [new file with mode: 0644]
dedup/templates/binary.html [new file with mode: 0644]
dedup/templates/compare.html [new file with mode: 0644]
dedup/templates/hash.html [new file with mode: 0644]
dedup/templates/index.html [new file with mode: 0644]
dedup/templates/source.html [new file with mode: 0644]
webapp.py

diff --git a/README b/README
index ef0ae48..a84807a 100644 (file)
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
 Required packages
 -----------------
 
-    aptitude install python python-debian python-lzma curl python-jinja2 python-werkzeug sqlite3 python-imaging python-yaml python-concurrent.futures
+    aptitude install python python-debian python-lzma curl python-jinja2 python-werkzeug sqlite3 python-imaging python-yaml python-concurrent.futures python-pkg-resources
 
 Create a database
 -----------------
diff --git a/base.html b/base.html
deleted file mode 100644 (file)
index 4e49d47..0000000
--- a/base.html
+++ /dev/null
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<html>
-       <head>
-               <title>{% block title %}{% endblock %}</title>
-               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-               <link  rel="stylesheet" type="text/css" href="{{ urlroot|e }}/style.css">
-               <link rel="icon" type="image/vnd.microsoft.icon" href="{{ urlroot|e }}/favicon.ico">
-               {% block header %}{% endblock %}
-       </head>
-       <body>
-{% block content %}
-{% endblock %}
-<hr>
-<h4>Details about this service</h4>
-<ul>
-       <li>More information: <a href="http://wiki.debian.org/dedup.debian.net">see wiki</a></li>
-       <li>Maintainer: Helmut Grohne &lt;helmut@subdivi.de&gt;</li>
-       <li>Source: git://murkel.subdivi.de/~helmut/debian-dedup.git</li>
-       <li>Bugs reports / Feedback / Patches: to the maintainer</li>
-</ul>
-       </body>
-</html>
diff --git a/dedup/templates/base.html b/dedup/templates/base.html
new file mode 100644 (file)
index 0000000..4e49d47
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+       <head>
+               <title>{% block title %}{% endblock %}</title>
+               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+               <link  rel="stylesheet" type="text/css" href="{{ urlroot|e }}/style.css">
+               <link rel="icon" type="image/vnd.microsoft.icon" href="{{ urlroot|e }}/favicon.ico">
+               {% block header %}{% endblock %}
+       </head>
+       <body>
+{% block content %}
+{% endblock %}
+<hr>
+<h4>Details about this service</h4>
+<ul>
+       <li>More information: <a href="http://wiki.debian.org/dedup.debian.net">see wiki</a></li>
+       <li>Maintainer: Helmut Grohne &lt;helmut@subdivi.de&gt;</li>
+       <li>Source: git://murkel.subdivi.de/~helmut/debian-dedup.git</li>
+       <li>Bugs reports / Feedback / Patches: to the maintainer</li>
+</ul>
+       </body>
+</html>
diff --git a/dedup/templates/binary.html b/dedup/templates/binary.html
new file mode 100644 (file)
index 0000000..59c910c
--- /dev/null
@@ -0,0 +1,31 @@
+{% 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 %}
diff --git a/dedup/templates/compare.html b/dedup/templates/compare.html
new file mode 100644 (file)
index 0000000..f78e80f
--- /dev/null
@@ -0,0 +1,27 @@
+{% 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 %}
diff --git a/dedup/templates/hash.html b/dedup/templates/hash.html
new file mode 100644 (file)
index 0000000..7141f96
--- /dev/null
@@ -0,0 +1,12 @@
+{% 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 %}
diff --git a/dedup/templates/index.html b/dedup/templates/index.html
new file mode 100644 (file)
index 0000000..7c9000f
--- /dev/null
@@ -0,0 +1,44 @@
+{% 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 dysfunctional 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 %}
diff --git a/dedup/templates/source.html b/dedup/templates/source.html
new file mode 100644 (file)
index 0000000..fc679b0
--- /dev/null
@@ -0,0 +1,15 @@
+{% 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 %}
index c080d41..e180087 100755 (executable)
--- 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""