From 0c27c95a9c55b82b2c7e5e90b885c87578e895d0 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 27 Jul 2013 09:32:03 +0200 Subject: move templates to dedup package They cluttered webapp.py and now vim can give proper highlighting for the templates. --- webapp.py | 146 +++----------------------------------------------------------- 1 file changed, 6 insertions(+), 140 deletions(-) (limited to 'webapp.py') 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 %}

{{ package|e }}

-

Version: {{ version|e }}

-

Architecture: {{ architecture|e }}

-

Number of files: {{ num_files }}

-

Total size: {{ total_size|filesizeformat }}

-{%- if shared -%} - {%- for function, sharing in shared.items() -%} -

sharing with respect to {{ function|e }}

- - {%- for entry in sharing|sort(attribute="savable", reverse=true) -%} - - {%- if entry.package %}{{ entry.package|e }}{% else %}self{% endif %} - compare - - - {%- endfor -%} -
packagefiles shareddata shared
{{ entry.duplicate }} ({{ (100 * entry.duplicate / num_files)|int }}%){{ entry.savable|filesizeformat }} ({{ (100 * entry.savable / total_size)|int }}%)
- {%- endfor -%} -

Note: Packages with yellow background are required to be installed when this package is installed.

-{%- endif -%} -{%- if issues -%} -

issues with particular files

- - {%- for filename, issue in issues|dictsort(true) -%} - - {%- endfor -%} -
filenameissue
{{ filename|e }}{{ issue|e }}
-{%- endif -%} -{% endblock %}""") - -detail_template = jinjaenv.from_string( -"""{% extends "base.html" %} -{% block title %}sharing between {{ details1.package|e }} and {{ details2.package|e }}{% endblock%} -{% block content %} -

{{ details1.package|e }} <-> {{ details2.package|e }}

-

Version of {{ details1.package|e }}: {{ details1.version|e }}

-

Architecture of {{ details1.package|e }}: {{ details1.architecture|e }}

-{%- if details1.package != details2.package -%} -

Version of {{ details2.package|e }}: {{ details2.version|e }}

-

Architecture of {{ details2.package|e }}: {{ details2.architecture|e }}

-{%- endif -%} - - -{%- for entry in shared -%} - 1 %} rowspan={{ entry.matches|length }}{% endif %}>{{ entry.size|filesizeformat }} 1 %} rowspan={{ entry.matches|length }}{% endif %}> - {%- for filename in entry.filenames %}{{ filename|e }}{% endfor -%} - {%- endfor -%} -{%- endfor -%} -
{{ details1.package|e }}{{ details2.package|e }}
sizefilenamehash functionsfilename
- {% for filename, match in entry.matches.items() -%} - {% if not loop.first %}
{% endif -%} - {%- for funccomb, hashvalue in match.items() -%} - {{ funccomb[0]|e }} - {%- if funccomb[0] != funccomb[1] %} -> {{ funccomb[1]|e }}{% endif %} - {%- if not loop.last %}, {% endif %} - {%- endfor -%} - {{ filename|e }}
-{% endblock %}""") - -hash_template = jinjaenv.from_string( -"""{% extends "base.html" %} -{% block title %}information on {{ function|e }} hash {{ hashvalue|e }}{% endblock %} -{% block content %} -

{{ function|e }} {{ hashvalue|e }}

- -{%- for entry in entries -%} - - - -{%- endfor -%} -
packagefilenamesizedifferent function
{{ entry.package|e }}{{ entry.filename|e }}{{ entry.size|filesizeformat }}{% if function != entry.function %}{{ entry.function|e }}{% endif %}
-{% endblock %}""") - -index_template = jinjaenv.from_string( -"""{% extends "base.html" %} -{% block title %}Debian duplication detector{% endblock %} -{% block header %} - -{% endblock %} -{% block content %} -

Debian duplication detector

- -{% 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|filesizeformat }}{{ sharing.package|e }} compare - {%- else -%}{%- endif -%} -
-

Note: Not all sharing listed here. Click on binary packages with non-zero savable to see more.

-{% 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"" -- cgit v1.2.3