From 1f6e833815c011e56ab77a258b4eee94a8acaf43 Mon Sep 17 00:00:00 2001 From: Valerie R Young Date: Mon, 11 Jul 2016 17:32:58 -0400 Subject: reproducible debian: move html from code into basic_page template Signed-off-by: Holger Levsen --- bin/reproducible_common.py | 30 ++++++++++++++---------------- bin/reproducible_html_pkg_sets.py | 33 ++++++++------------------------- bin/templates/basic_page.mustache | 20 ++++++++++++++++---- 3 files changed, 38 insertions(+), 45 deletions(-) diff --git a/bin/reproducible_common.py b/bin/reproducible_common.py index 95b652e3..70a4f62c 100755 --- a/bin/reproducible_common.py +++ b/bin/reproducible_common.py @@ -155,6 +155,8 @@ project_links_template = renderer.load_template( os.path.join(TEMPLATE_PATH, 'project_links')) main_navigation_template = renderer.load_template( os.path.join(TEMPLATE_PATH, 'main_navigation')) +basic_page_template = renderer.load_template( + os.path.join(TEMPLATE_PATH, 'basic_page')) html_header = Template(""" @@ -278,32 +280,28 @@ def create_main_navigation(page_title, suite, arch, displayed_page=None): def write_html_page(title, body, destfile, suite=defaultsuite, arch=defaultarch, noheader=False, style_note=False, noendpage=False, packages=False, refresh_every=None, displayed_page=None): - now = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC') - html = '' meta_refresh = '' % \ refresh_every if refresh_every is not None else '' - html += html_header.substitute( - page_title=title, - meta_refresh=meta_refresh) + context = { + 'page_title': title, + 'meta_refresh': meta_refresh, + } if not noheader: - html += create_main_navigation( + context['main_navigation_html'] = create_main_navigation( page_title=title, suite=suite, arch=arch, displayed_page=displayed_page, ) - # Add the 'mainbody' div only if including a header - html += "
" - html += body + main_html = body if style_note: - html += renderer.render(pkg_legend_template, {}) + main_html += renderer.render(pkg_legend_template, {}) if not noendpage: - html += create_default_page_footer(now) - if not noheader: - # If the header was included, we need to end the 'mainbody' div after - # the 'mainbody' content - html += '
' - html += '\n' + now = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC') + main_html += create_default_page_footer(now) + context['main_html'] = main_html + html = renderer.render(basic_page_template, context) + try: os.makedirs(destfile.rsplit('/', 1)[0], exist_ok=True) except OSError as e: diff --git a/bin/reproducible_html_pkg_sets.py b/bin/reproducible_html_pkg_sets.py index 89652aa5..f5dc9fab 100755 --- a/bin/reproducible_html_pkg_sets.py +++ b/bin/reproducible_html_pkg_sets.py @@ -24,8 +24,6 @@ pkgset_navigation_template = renderer.load_template( os.path.join(TEMPLATE_PATH, 'pkgset_navigation')) pkgset_details_template = renderer.load_template( os.path.join(TEMPLATE_PATH, 'pkgset_details')) -basic_page_template = renderer.load_template( - os.path.join(TEMPLATE_PATH, 'basic_page')) pkg_legend_template = renderer.load_template( os.path.join(TEMPLATE_PATH, 'pkg_symbol_legend')) @@ -140,20 +138,13 @@ def create_pkgset_navigation(suite, arch, view=None): def create_index_page(suite, arch): title = 'Package sets in %s/%s for Reproducible Builds' % (suite, arch) - now = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC') - page_context = { - 'main_html': create_pkgset_navigation(suite, arch) + - create_default_page_footer(now), - 'main_navigation_html': create_main_navigation(title, suite, arch, - 'pkg_set'), - } - body = renderer.render(basic_page_template, page_context) + body = create_pkgset_navigation(suite, arch) destfile = os.path.join(DEBIAN_BASE, suite, arch, "index_pkg_sets.html") log.info("Creating pkgset index page for %s/%s.", suite, arch) - write_html_page(title=title, body=body, destfile=destfile, - noheader=True, noendpage=True) + write_html_page(title=title, body=body, destfile=destfile, suite=suite, + arch=arch, displayed_page='pkg_set') def gen_other_arch_context(archs, suite, pkgset_name): @@ -184,8 +175,8 @@ def stats_thumb_file_href(suite, arch, pkgset_name): def create_pkgset_page_and_graphs(suite, arch, stats, pkgset_name): - html = "" - html += create_pkgset_navigation(suite, arch, pkgset_name) + html_body = "" + html_body += create_pkgset_navigation(suite, arch, pkgset_name) pkgset_context = ({ 'pkgset_name': pkgset_name, 'suite': suite, @@ -241,23 +232,15 @@ def create_pkgset_page_and_graphs(suite, arch, stats, pkgset_name): stats["count_" + cutename] != 0): pkgset_context['status_details'].append(details_context) - html += renderer.render(pkgset_details_template, pkgset_context) - now = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC') - html += create_default_page_footer(now) + html_body += renderer.render(pkgset_details_template, pkgset_context) title = 'Reproducible Builds %s package set for %s/%s for' % \ (pkgset_name, suite, arch) - - body = renderer.render(basic_page_template, { - 'main_html': html, - 'main_navigation_html': create_main_navigation(title, suite, arch, - 'pkg_set'), - }) page = "pkg_set_" + pkgset_name + ".html" destfile = os.path.join(DEBIAN_BASE, suite, arch, page) log.info("Creating meta pkgset page for %s in %s/%s.", pkgset_name, suite, arch) - write_html_page(title=title, body=body, destfile=destfile, - noheader=True, noendpage=True) + write_html_page(title=title, body=html_body, destfile=destfile, suite=suite, + arch=arch, displayed_page='pkg_set') def create_pkgset_graph(png_file, suite, arch, pkgset_name): diff --git a/bin/templates/basic_page.mustache b/bin/templates/basic_page.mustache index 99fee20f..1239a4a0 100644 --- a/bin/templates/basic_page.mustache +++ b/bin/templates/basic_page.mustache @@ -1,4 +1,16 @@ -{{{main_navigation_html}}} -
-{{{main_html}}} -
+ + + + + + {{meta_refresh}} + + {{page_title}} + + + {{{main_navigation_html}}} +
+ {{{main_html}}} +
+ + -- cgit v1.2.3-70-g09d2