From 33e668c4571e06effe56eaa7dc5884412a2707d2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 8 May 2012 19:42:09 +0000 Subject: [PATCH] pkg version template --- po/Makefile | 2 +- po/Makefile.in | 2 +- po/fr.po | 42 +++++++++++------- po/ppastats.pot | 37 +++++++++++----- src/html.c | 123 +++++++++++++++++++++++++++++++--------------------- www/header.tpl | 7 ++- www/pkg_version.tpl | 48 +++++++------------- 7 files changed, 148 insertions(+), 113 deletions(-) diff --git a/po/Makefile b/po/Makefile index b5acc35..69bf449 100644 --- a/po/Makefile +++ b/po/Makefile @@ -22,7 +22,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp/p +prefix = /usr exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/po/Makefile.in b/po/Makefile.in index 9fdca0c..cbbdd55 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -22,7 +22,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp/p +prefix = /usr exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/po/fr.po b/po/fr.po index 83070bc..833fb55 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ppastats 0.0.x\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2012-05-07 23:24+0200\n" +"POT-Creation-Date: 2012-05-08 15:00+0200\n" "PO-Revision-Date: 2012-05-05 23:45+0200\n" "Last-Translator: \n" "Language-Team: French\n" @@ -31,19 +31,33 @@ msgstr "" msgid "exceed cache capacity" msgstr "" -#: src/html.c:408 src/html.c:437 +#: src/html.c:378 #, c-format msgid "failed to open: %s" msgstr "" -#: src/html.c:478 src/html.c:505 src/html.c:518 +#: src/html.c:406 +msgid "Failed to get the header template" +msgstr "" + +#: src/html.c:413 +#, c-format +msgid "Failed to open: %s" +msgstr "" + +#: src/html.c:454 #, c-format msgid "generating %s" msgstr "" -#: src/html.c:581 +#: src/html.c:481 src/html.c:494 #, c-format -msgid "copying %s %s" +msgid "Generating %s" +msgstr "" + +#: src/html.c:557 +#, c-format +msgid "Copying %s %s" msgstr "" #: src/log.c:37 @@ -51,25 +65,26 @@ msgstr "" msgid "Cannot open log file: %s" msgstr "" -#: src/lp_ws.c:68 +#: src/lp_ws.c:69 msgid "initializing CURL" msgstr "" -#: src/lp_ws.c:84 +#: src/lp_ws.c:86 #, c-format msgid "fetch_url(): %s" msgstr "" -#: src/lp_ws.c:114 src/lp_ws.c:129 +#: src/lp_ws.c:116 src/lp_ws.c:132 #, c-format msgid "Fetch failed with code %ld for URL %s" msgstr "" -#: src/lp_ws.c:119 -msgid "Wait 5s before retry" +#: src/lp_ws.c:122 +#, c-format +msgid "Wait %ds before retry" msgstr "" -#: src/lp_ws.c:303 +#: src/lp_ws.c:306 msgid "cleanup CURL" msgstr "" @@ -118,11 +133,8 @@ msgstr "" " -v, --version afficher les informations de version et quitter" #: src/main.c:123 -#, fuzzy msgid " -v, --version display version information and exit" -msgstr "" -" -h, --help afficher cette aide et quitter\n" -" -v, --version afficher les informations de version et quitter" +msgstr " -v, --version afficher les informations de version et quitter" #: src/main.c:127 msgid " -o, --output-dir=[PATH] generates HTML pages into 'PATH'" diff --git a/po/ppastats.pot b/po/ppastats.pot index 14dc0ee..770c39b 100644 --- a/po/ppastats.pot +++ b/po/ppastats.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ppastats 0.0.x\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2012-05-07 23:24+0200\n" +"POT-Creation-Date: 2012-05-08 15:00+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -31,19 +31,33 @@ msgstr "" msgid "exceed cache capacity" msgstr "" -#: src/html.c:408 src/html.c:437 +#: src/html.c:378 #, c-format msgid "failed to open: %s" msgstr "" -#: src/html.c:478 src/html.c:505 src/html.c:518 +#: src/html.c:406 +msgid "Failed to get the header template" +msgstr "" + +#: src/html.c:413 +#, c-format +msgid "Failed to open: %s" +msgstr "" + +#: src/html.c:454 #, c-format msgid "generating %s" msgstr "" -#: src/html.c:581 +#: src/html.c:481 src/html.c:494 #, c-format -msgid "copying %s %s" +msgid "Generating %s" +msgstr "" + +#: src/html.c:557 +#, c-format +msgid "Copying %s %s" msgstr "" #: src/log.c:37 @@ -51,25 +65,26 @@ msgstr "" msgid "Cannot open log file: %s" msgstr "" -#: src/lp_ws.c:68 +#: src/lp_ws.c:69 msgid "initializing CURL" msgstr "" -#: src/lp_ws.c:84 +#: src/lp_ws.c:86 #, c-format msgid "fetch_url(): %s" msgstr "" -#: src/lp_ws.c:114 src/lp_ws.c:129 +#: src/lp_ws.c:116 src/lp_ws.c:132 #, c-format msgid "Fetch failed with code %ld for URL %s" msgstr "" -#: src/lp_ws.c:119 -msgid "Wait 5s before retry" +#: src/lp_ws.c:122 +#, c-format +msgid "Wait %ds before retry" msgstr "" -#: src/lp_ws.c:303 +#: src/lp_ws.c:306 msgid "cleanup CURL" msgstr "" diff --git a/src/html.c b/src/html.c index f2d39bb..8a12524 100644 --- a/src/html.c +++ b/src/html.c @@ -35,6 +35,7 @@ #include "lp.h" #include "lp_ws.h" #include "ppastats.h" +#include "str.h" static const char *footer; static const char *ppa_body; @@ -60,19 +61,35 @@ static char *path_new(const char *dir, const char *file, const char *suffixe) return path; } -static const char *get_header() +static char *get_header(const char *title, const char *script) { const char *path; + char *res, *tmp; if (!header) { path = DEFAULT_WWW_DIR"/header.tpl"; header = file_get_content(path); - if (!header) + if (!header) { log_err("Failed to read header template: %s", path); + + return NULL; + } } - return header; + tmp = strdup(header); + res = strrep(tmp, "@SCRIPT@", script); + + if (res != tmp) + free(tmp); + + tmp = res; + res = strrep(tmp, "@TITLE@", title); + + if (res != tmp) + free(tmp); + + return res; } static const char *get_footer() @@ -352,46 +369,6 @@ static json_object *ppa_to_json(struct ppa_stats *ppa) } static void -version_to_html(struct ppa_stats *ppa, - struct package_stats *pkg, - struct version_stats *version, - const char *dir) -{ - 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); - - path = path_new(dir, f_name, ".html"); - f = fopen(path, "w"); - - if (!f) { - log_err(_("failed to open: %s"), path); - return ; - } - - fprintf(f, pkg_ver, version_to_json(ppa, pkg, version)); - - footer = get_footer(); - if (footer) - fputs(footer, f); - - fclose(f); - - free(path); - free(f_name); -} - -static void create_html(const char *path, const char *title, const char *body_template, @@ -399,29 +376,36 @@ create_html(const char *path, { FILE *f; const char *footer; - const char *header; + char *header; - header = get_header(); + f = NULL; + + header = get_header(title, script); if (!header) { log_err(_("Failed to get the header template")); - return ; + goto on_error; } f = fopen(path, "w"); if (!f) { log_err(_("Failed to open: %s"), path); - return ; + goto on_error; } - fprintf(f, header, title, script); + fputs(header, f); fputs(body_template, f); footer = get_footer(); if (footer) fputs(footer, f); - fclose(f); + on_error: + if (header) + free(header); + + if (f) + fclose(f); } static char *ppa_display_name(const struct ppa_stats *ppa) @@ -464,6 +448,47 @@ index_to_html(struct ppa_stats *ppa, const char *dir) } static void +version_to_html(struct ppa_stats *ppa, + struct package_stats *pkg, + struct version_stats *version, + const char *dir) +{ + char *f_name, *path; + const char *body; + const char *script_tpl; + char *script, *json; + + body = get_pkg_version_body(); + if (!body) { + log_err("Failed to create package version page"); + return ; + } + + json = version_to_json(ppa, pkg, version); + if (!json) { + log_err("Failed to create package version page"); + return ; + } + + + f_name = malloc(strlen(pkg->name)+1+strlen(version->version)+1); + sprintf(f_name, "%s_%s", pkg->name, version->version); + + path = path_new(dir, f_name, ".html"); + + script_tpl = "var data = %s;\n ppastats_ver();"; + script = malloc(strlen(script_tpl) - 2 +strlen(json) + 1); + sprintf(script, script_tpl, json); + + create_html(path, f_name, body, script); + + free(json); + free(path); + free(f_name); + +} + +static void pkg_to_html(struct ppa_stats *ppa, struct package_stats *pkg, const char *dir) { char *path, *json_path, *script; diff --git a/www/header.tpl b/www/header.tpl index c9f3552..0bd0327 100644 --- a/www/header.tpl +++ b/www/header.tpl @@ -1,8 +1,7 @@ - %s - @TITLE@ + @@ -11,7 +10,7 @@ - + diff --git a/www/pkg_version.tpl b/www/pkg_version.tpl index bdcfe61..182c119 100644 --- a/www/pkg_version.tpl +++ b/www/pkg_version.tpl @@ -1,33 +1,17 @@ - - - - - - - - - - - - - -

N/A

-
Version:
-

PPA: - - N/A/N/A - -

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

    N/A

    +
    Version:
    +

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

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