From 904cc6ab0bff6e4b31d5782839c07aeef0d95b6c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 8 May 2012 12:59:04 +0000 Subject: [PATCH] read pkg version template from file --- src/html.c | 75 ++++++++++++++++++++--------------------------------- www/Makefile.am | 1 + www/Makefile.in | 1 + www/pkg_version.tpl | 33 +++++++++++++++++++++++ 4 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 www/pkg_version.tpl diff --git a/src/html.c b/src/html.c index 75a562f..f2d39bb 100644 --- a/src/html.c +++ b/src/html.c @@ -36,51 +36,11 @@ #include "lp_ws.h" #include "ppastats.h" -static char *footer; -static char *ppa_body; -static char *pkg_body; -static char *header; - -#define HTML_VERSION_TEMPLATE \ -"\n\ - \n\ - \n\ - \n\ - \n\ -\n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ -

N/A

\n\ -
Version:
\n\ -

PPA: \n\ - \n\ - N/A/N/A\n\ -

\n\ -
\n\ -
\n\ -
\n\ -
\n\ -
\n\ - Distros:\n\ -
    \n\ -
    \n\ -
    \n" +static const char *footer; +static const char *ppa_body; +static const char *pkg_body; +static const char *pkg_version_body; +static const char *header; static char *path_new(const char *dir, const char *file, const char *suffixe) { @@ -130,6 +90,21 @@ static const char *get_footer() return footer; } +static const char *get_pkg_version_body() +{ + const char *path; + + if (!pkg_version_body) { + path = DEFAULT_WWW_DIR"/pkg_version.tpl"; + pkg_version_body = file_get_content(path); + + if (!pkg_version_body) + log_err("Failed to read package version template: %s", + path); + } + + return pkg_version_body; +} static const char *get_ppa_body() { const char *path; @@ -385,6 +360,13 @@ version_to_html(struct ppa_stats *ppa, char *f_name, *path; FILE *f; const char *footer; + const char *pkg_ver; + + pkg_ver = get_pkg_version_body(); + if (!pkg_ver) { + log_err("Failed to get package version template"); + return ; + } f_name = malloc(strlen(pkg->name)+1+strlen(version->version)+1); sprintf(f_name, "%s_%s", pkg->name, version->version); @@ -397,8 +379,7 @@ version_to_html(struct ppa_stats *ppa, return ; } - fprintf(f, HTML_VERSION_TEMPLATE, - version_to_json(ppa, pkg, version)); + fprintf(f, pkg_ver, version_to_json(ppa, pkg, version)); footer = get_footer(); if (footer) diff --git a/www/Makefile.am b/www/Makefile.am index 7489d23..1dc9534 100644 --- a/www/Makefile.am +++ b/www/Makefile.am @@ -10,6 +10,7 @@ defaultwww_DATA = \ css/ppastats.css\ css/jquery.jqplot.min.css\ pkg.tpl\ + pkg_version.tpl\ ppa.tpl EXTRA_DIST=$(defaultwww_DATA) diff --git a/www/Makefile.in b/www/Makefile.in index 5c98628..4d8a094 100644 --- a/www/Makefile.in +++ b/www/Makefile.in @@ -215,6 +215,7 @@ defaultwww_DATA = \ css/ppastats.css\ css/jquery.jqplot.min.css\ pkg.tpl\ + pkg_version.tpl\ ppa.tpl EXTRA_DIST = $(defaultwww_DATA) diff --git a/www/pkg_version.tpl b/www/pkg_version.tpl new file mode 100644 index 0000000..bdcfe61 --- /dev/null +++ b/www/pkg_version.tpl @@ -0,0 +1,33 @@ + + + + + + + + + + + + + +

    N/A

    +
    Version:
    +

    PPA: + + N/A/N/A + +

    +
    +
    +
    +
    +
    + Distros: +
      +
      +
      + -- 2.7.4