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. --- README | 2 +- base.html | 22 ------- dedup/templates/base.html | 22 +++++++ dedup/templates/binary.html | 31 +++++++++ dedup/templates/compare.html | 27 ++++++++ dedup/templates/hash.html | 12 ++++ dedup/templates/index.html | 44 +++++++++++++ dedup/templates/source.html | 15 +++++ webapp.py | 146 ++----------------------------------------- 9 files changed, 158 insertions(+), 163 deletions(-) delete mode 100644 base.html create mode 100644 dedup/templates/base.html create mode 100644 dedup/templates/binary.html create mode 100644 dedup/templates/compare.html create mode 100644 dedup/templates/hash.html create mode 100644 dedup/templates/index.html create mode 100644 dedup/templates/source.html diff --git a/README b/README index ef0ae48..a84807a 100644 --- 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 index 4e49d47..0000000 --- a/base.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - {% block title %}{% endblock %} - - - - {% block header %}{% endblock %} - - -{% block content %} -{% endblock %} -
-

Details about this service

- - - diff --git a/dedup/templates/base.html b/dedup/templates/base.html new file mode 100644 index 0000000..4e49d47 --- /dev/null +++ b/dedup/templates/base.html @@ -0,0 +1,22 @@ + + + + {% block title %}{% endblock %} + + + + {% block header %}{% endblock %} + + +{% block content %} +{% endblock %} +
+

Details about this service

+ + + diff --git a/dedup/templates/binary.html b/dedup/templates/binary.html new file mode 100644 index 0000000..59c910c --- /dev/null +++ b/dedup/templates/binary.html @@ -0,0 +1,31 @@ +{% 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 %} diff --git a/dedup/templates/compare.html b/dedup/templates/compare.html new file mode 100644 index 0000000..f78e80f --- /dev/null +++ b/dedup/templates/compare.html @@ -0,0 +1,27 @@ +{% 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 %} diff --git a/dedup/templates/hash.html b/dedup/templates/hash.html new file mode 100644 index 0000000..7141f96 --- /dev/null +++ b/dedup/templates/hash.html @@ -0,0 +1,12 @@ +{% 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 %} diff --git a/dedup/templates/index.html b/dedup/templates/index.html new file mode 100644 index 0000000..7c9000f --- /dev/null +++ b/dedup/templates/index.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} +{% block title %}Debian duplication detector{% endblock %} +{% block header %} + +{% endblock %} +{% block content %} +

Debian duplication detector

+ +{% endblock %} diff --git a/dedup/templates/source.html b/dedup/templates/source.html new file mode 100644 index 0000000..fc679b0 --- /dev/null +++ b/dedup/templates/source.html @@ -0,0 +1,15 @@ +{% 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 %} 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