/*
- Copyright (C) 2011 jeanfi@gmail.com
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301 USA
-*/
+ * Copyright (C) 2011-2012 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <libintl.h>
+#define _(String) gettext(String)
#include <stdio.h>
#include <stdlib.h>
#include "html.h"
#include "io.h"
+#include "log.h"
#include "lp.h"
#include "lp_ws.h"
#include "ppastats.h"
-#define HTML_FOOTER \
-" <div id=\"footer\">Generated by \
-<a href='http://wpitchoune.net/ppastats'>ppastats</a></div>\n\
- </body>\n\
-</html>"
+static char *footer;
#define HTML_PKG_TEMPLATE \
" <h1><span id=\"pkg_name\">N/A</span></h1>\n\
<link type=\"text/css\" href=\"css/ppastats.css\" rel=\"stylesheet\" />\n\
<link type=\"text/css\" href=\"css/jquery.jqplot.min.css\"\n\
rel=\"stylesheet\" />\n\
+<!--[if lt IE 9]><script \
+language=\"javascript\" \
+type=\"text/javascript\" \
+src=\"js/excanvas.js\"></script><![endif]-->\n\
<script type=\"text/javascript\" src=\"js/jquery.min.js\"></script>\n\
<script type=\"text/javascript\"\n\
src=\"js/jquery.jqplot.min.js\"></script>\n\
<em>Distros</em>:\n\
<ul id=\"distros\"></ul>\n\
</div>\n\
- </div>\n\
-%s"
+ </div>\n"
#define HTML_HEADER \
"<html>\n\
static char *path_new(const char *dir, const char *file, const char *suffixe)
{
- char *path = malloc(strlen(dir)+1+
- strlen(file)+
- strlen(".html")+
- (suffixe ? strlen(suffixe) : 0) +
- 1);
+ char *path;
+
+ /* [dir]/[file][suffixe] */
+ path = malloc(strlen(dir)+1+
+ strlen(file)+
+ (suffixe ? strlen(suffixe) : 0) +
+ 1);
strcpy(path, dir);
strcat(path, "/");
return path;
}
+
+
+static const char *get_footer()
+{
+ const char *path;
+
+ if (!footer) {
+ path = DEFAULT_WWW_DIR"/footer.tpl";
+ footer = file_get_content(path);
+
+ if (!footer)
+ log_err("Failed to read footer template: %s", path);
+ }
+
+ return footer;
+}
+
static struct json_object *date_to_json(struct tm *tm)
{
json_object *json;
{
char *f_name, *path;
FILE *f;
+ const char *footer;
f_name = malloc(strlen(pkg->name)+1+strlen(version->version)+1);
sprintf(f_name, "%s_%s", pkg->name, version->version);
f = fopen(path, "w");
if (!f) {
- fprintf(stderr, "ERROR: failed to open: %s\n", path);
+ log_err(_("failed to open: %s"), path);
return ;
}
fprintf(f, HTML_VERSION_TEMPLATE,
- version_to_json(ppa, pkg, version),
- HTML_FOOTER);
+ version_to_json(ppa, pkg, version));
+
+ footer = get_footer();
+ if (footer)
+ fputs(footer, f);
fclose(f);
const char *script)
{
FILE *f;
+ const char *footer;
f = fopen(path, "w");
if (!f) {
- fprintf(stderr, "ERROR: failed to open: %s\n", path);
+ log_err(_("failed to open: %s"), path);
return ;
}
fprintf(f, HTML_HEADER, title, script);
fputs(body_template, f);
- fputs(HTML_FOOTER, f);
+
+ footer = get_footer();
+ if (footer)
+ fputs(footer, f);
fclose(f);
}
json = ppa_to_json(ppa);
json_path = path_new(dir, "index", ".json");
- if (debug)
- printf("DEBUG: generating %s\n", json_path);
+
+ log_debug(_("generating %s"), json_path);
json_object_to_file(json_path, json);
json_object_put(json);
free(json_path);
json_path = path_new(dir, pkg->name, ".json");
json = pkg_to_json(ppa, pkg);
- if (debug)
- printf("DEBUG: generating %s\n", json_path);
+ log_debug(_("generating %s"), json_path);
+
json_object_to_file(json_path, json);
json_object_put(json);
free(json_path);
1);
sprintf(script, "ppastats_pkg(\"%s%s\");", pkg->name, ".json");
- if (debug)
- printf("DEBUG: generating %s\n", path);
+ log_debug(_("generating %s"), path);
create_html(path, pkg->name, HTML_PKG_TEMPLATE, script);
free(path);
for (i = 0; i < 7; i++) {
f_dst = path_append(output_dir, www_files[2*i+1]);
- if (debug)
- printf("DEBUG: copying %s %s\n",
- www_files[2*i], f_dst);
+ log_debug(_("copying %s %s"), www_files[2*i], f_dst);
fcopy(www_files[2*i], f_dst);
free(f_dst);