X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fhtml.c;fp=src%2Fhtml.c;h=4eddeb3f8af13d7c8af6a050977ca170f99ff261;hb=eab64e6ecb435face78646153fe86c22895d8f41;hp=c0dd7678869d066cce487d7bf392e500cade0263;hpb=df19eac22b08c4793607679e2ea471ae64b824fd;p=ppastats.git
diff --git a/src/html.c b/src/html.c
index c0dd767..4eddeb3 100644
--- a/src/html.c
+++ b/src/html.c
@@ -112,38 +112,41 @@
\n\
%s"
-#define HTML_INDEX_TEMPLATE \
+#define HTML_HEADER \
"\n\
-
\n\
- \n\
+ %s\n\
+ \n\
- \n\
- \n\
- \n\
- \n\
- \n\
- \n\
- \n\
- \n\
- \n\
- N/A
\n\
- \n\
-
\n\
-
Packages:\n\
-
\n\
-
\n\
-
\n\
- \n\
-%s"
+ \n\
+ \n\
+ \n\
+ \n\
+ \n\
+ \n\
+ \n\
+ \n\
+ \n"
+
+#define HTML_INDEX_TEMPLATE \
+" N/A
\n\
+ \n\
+
\n\
+
Packages:\n\
+
\n\
+
\n\
+
\n\
+ \n"
static char *path_new(const char *dir, const char *file, const char *suffixe)
{
@@ -156,7 +159,7 @@ static char *path_new(const char *dir, const char *file, const char *suffixe)
strcpy(path, dir);
strcat(path, "/");
strcat(path, file);
- strcat(path, ".html");
+ strcat(path, suffixe);
return path;
}
@@ -332,9 +335,8 @@ static char *version_to_json(struct ppa_stats *ppa,
return ret;
}
-static char *ppa_to_json(struct ppa_stats *ppa)
+static json_object *ppa_to_json(struct ppa_stats *ppa)
{
- char *ret;
json_object *json, *json_pkgs, *json_pkg;
struct package_stats **pkgs;
@@ -365,11 +367,7 @@ static char *ppa_to_json(struct ppa_stats *ppa)
pkgs++;
}
- ret = strdup(json_object_to_json_string(json));
-
- json_object_put(json);
-
- return ret;
+ return json;
}
@@ -452,12 +450,13 @@ packages_to_html(struct ppa_stats *ppa,
}
static void
-index_to_html(struct ppa_stats *ppa, const char *dir)
+create_html(const char *path,
+ const char *title,
+ const char *body_template,
+ const char *script)
{
- char *path;
FILE *f;
- path = path_new(dir, "index", ".html");
f = fopen(path, "w");
if (!f) {
@@ -465,11 +464,49 @@ index_to_html(struct ppa_stats *ppa, const char *dir)
return ;
}
- fprintf(f, HTML_INDEX_TEMPLATE, ppa_to_json(ppa), HTML_FOOTER);
+ fprintf(f, HTML_HEADER, title, script);
+ fputs(HTML_INDEX_TEMPLATE, f);
+ fputs(HTML_FOOTER, f);
fclose(f);
+}
+
+static char *ppa_display_name(const struct ppa_stats *ppa)
+{
+ char *ret;
+
+ ret = malloc(4+strlen(ppa->name)+1+strlen(ppa->owner)+1);
+
+ sprintf(ret, "ppa:%s/%s", ppa->owner, ppa->name);
+
+ return ret;
+}
+
+static void
+index_to_html(struct ppa_stats *ppa, const char *dir)
+{
+ char *path, *json_path, *dname;
+ json_object *json;
+
+ json = ppa_to_json(ppa);
+
+ json_path = path_new(dir, "index", ".json");
+
+ if (debug)
+ printf("DEBUG: generating %s\n", json_path);
+
+ json_object_to_file(json_path, json);
+
+ json_object_put(json);
+
+ path = path_new(dir, "index", ".html");
+ dname = ppa_display_name(ppa);
+
+ create_html(path, dname, HTML_INDEX_TEMPLATE, "ppastats_ppa();");
free(path);
+ free(dname);
+ free(json_path);
}
void
@@ -495,6 +532,8 @@ ppa_to_html(const char *owner,
DEFAULT_WWW_DIR"/jquery.jqplot.min.css",
"css/jquery.jqplot.min.css" };
+ mkdirs(output_dir, 0777);
+
if (install_static_files) {
css_dir = path_append(output_dir, "css");
js_dir = path_append(output_dir, "js");
@@ -504,6 +543,10 @@ ppa_to_html(const char *owner,
for (i = 0; i < 6; 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);
fcopy(www_files[2*i], f_dst);
free(f_dst);