generate html page for the ppa itself
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 3 Sep 2011 16:45:49 +0000 (16:45 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 3 Sep 2011 16:45:49 +0000 (16:45 +0000)
NEWS
src/html.c
src/main.c
www/js/ppastats.js

diff --git a/NEWS b/NEWS
index 57c85c9..91c7cf4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
 ** Fixed memory issue (patch submitted by Lekensteyn).
 ** Added help for -s option.
 ** Don't generate manpage if help2man not present.
+** Generate html page for the PPA.
 
 * v0.0.3
 ** Generated HTML pages for package versions.
index 6ae462d..a903009 100644 (file)
@@ -105,6 +105,37 @@ enum file_copy_error {
   </body>\n\
 </html>"
 
+#define HTML_INDEX_TEMPLATE \
+"<html>\n\
+  <head>\n\
+    <link type=\"text/css\"\n\
+         rel=\"stylesheet\"\n\
+         href=\n\
+\"http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin\">\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\
+    <script type=\"text/javascript\" src=\"js/jquery.min.js\"></script>\n\
+    <script type=\"text/javascript\"\n\
+           src=\"js/jquery.jqplot.min.js\"></script>\n\
+    <script type=\"text/javascript\"\n\
+           src=\"js/jqplot.dateAxisRenderer.min.js\"></script>\n\
+    <script type=\"text/javascript\" src=\"js/ppastats.js\"></script>\n\
+    <script>var data = %s;\n\
+           ppastats_ppa();\n\
+    </script>\n\
+  </head>\n\
+  <body>\n\
+    <h1><span id=\"ppa_name\">N/A</span></h1>\n\
+    <div class=\"pkgs\">\n\
+       <em>Packages</em>:\n\
+       <ul id=\"pkgs\"></ul>\n\
+    </div>\n\
+    <div id=\"chart\"></div>\n\
+  </body>\n\
+</html>"
+
+
 #define FCOPY_BUF_SZ 4096
 static int file_copy(FILE * src, FILE * dst)
 {
@@ -323,6 +354,47 @@ static char *version_to_json(struct ppa_stats *ppa,
        return ret;
 }
 
+static char *ppa_to_json(struct ppa_stats *ppa)
+{
+       char *ret;
+       json_object *json, *json_pkgs, *json_pkg;
+       struct package_stats **pkgs;
+
+       json = json_object_new_object();
+
+       json_object_object_add(json,
+                              "ppa_name", json_object_new_string(ppa->name));
+       json_object_object_add(json,
+                              "ppa_owner",
+                              json_object_new_string(ppa->owner));
+
+       json_add_ddts(json, ppa->daily_download_totals);
+
+       pkgs = ppa->packages;
+       json_pkgs = json_object_new_array();
+       json_object_object_add(json, "packages", json_pkgs);
+       while (*pkgs) {
+               json_pkg = json_object_new_object();
+               json_object_array_add(json_pkgs, json_pkg);
+
+               json_object_object_add(json_pkg, "name",
+                                      json_object_new_string((*pkgs)->name));
+
+               json_object_object_add
+                       (json_pkg, "count",
+                        json_object_new_int((*pkgs)->download_count));
+
+               pkgs++;
+       }
+
+       ret = strdup(json_object_to_json_string(json));
+
+       json_object_put(json);
+
+       return ret;
+}
+
+
 static void
 pkg_to_html(struct ppa_stats *ppa, struct package_stats *pkg, const char *dir)
 {
@@ -399,6 +471,27 @@ packages_to_html(struct ppa_stats *ppa,
        }
 }
 
+static void
+index_to_html(struct ppa_stats *ppa, const char *dir)
+{
+       char *path;
+       FILE *f;
+
+       path = get_path(dir, "index");
+       f = fopen(path, "w");
+
+       if (!f) {
+               fprintf(stderr, "ERROR: failed to open: %s\n", path);
+               return ;
+       }
+
+       fprintf(f, HTML_INDEX_TEMPLATE, ppa_to_json(ppa));
+
+       fclose(f);
+
+       free(path);
+}
+
 static char *append_path(const char *odir, const char *name)
 {
        char *dir;
@@ -452,6 +545,8 @@ ppa_to_html(const char *owner,
 
        packages_to_html(ppastats, ppastats->packages, output_dir);
 
+       index_to_html(ppastats, output_dir);
+
        ppa_stats_free(ppastats);
 
        free(path);
index 2314f81..c9a94fd 100644 (file)
@@ -126,7 +126,7 @@ static void print_help()
 generates HTML pages into 'PATH'.");
 
        puts("\
-  -s, --status=[STATUS]        retrieves only package of the given status\n\
+  -s, --status=[STATUS]                retrieves only package of the given status\n\
                                (possible values are: Pending, Published, \n\
                                Superseded, Deleted or Obsolete).");
 
index 43c75be..e0bd70e 100644 (file)
@@ -98,4 +98,51 @@ function ppastats_ver() {
     });
 }
                      
+function ppastats_ppa() {
+    $(document).ready(function() {
+       var data_chart = [];
+       var ddts = data["ddts"];
+       var max_date = null;
+       var min_date = null;
+       var pkg_url = data["pkg_name"]+".html";
+       
+       $("#ppa_name").html(data["ppa_owner"]+"/"+data["ppa_name"]);
+
+       $.each(ddts, function(i, item) {
+            var tm = item["time"];
+            var d = new Date(tm[0], tm[1]-1, tm[2], 0, 0, 0, 0);
+            var entry = [d, item["value"]];
+            data_chart.push(entry);
+           
+            if (max_date == null || max_date < d) {
+               max_date = d;
+            }
+           
+            if (min_date == null || min_date > d) { 
+               min_date = d;
+            }
+       });
+
+       $.each(data["packages"], function(i, item) {
+           var url = item["name"]+".html";
+           $("#pkgs").append("<li><a href='"+url+"'>"+item["name"]+"</a>: "+item["count"]+"</li>");
+       });
+
+       var plot1 = $.jqplot ('chart', [data_chart], {
+            axes: {
+               xaxis: {
+                    renderer:$.jqplot.DateAxisRenderer,
+                    tickOptions:{formatString:'%Y/%m/%d'},
+                    min: min_date,
+                    max: max_date
+               },
+               yaxis: {
+                    min: 0
+               }
+            },
+            series: [{lineWidth:1,showMarker:false}]
+       });
+    });
+}
+                     
                      
\ No newline at end of file