ppastats_SOURCES = \
cache.h cache.c\
html.h html.c\
+ list.h list.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
main.c\
- ppastats.h
+ ppastats.h ppastats.c
dist_man_MANS = ppastats.1
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
-am_ppastats_OBJECTS = cache.$(OBJEXT) html.$(OBJEXT) lp.$(OBJEXT) \
- lp_json.$(OBJEXT) lp_ws.$(OBJEXT) main.$(OBJEXT)
+am_ppastats_OBJECTS = cache.$(OBJEXT) html.$(OBJEXT) list.$(OBJEXT) \
+ lp.$(OBJEXT) lp_json.$(OBJEXT) lp_ws.$(OBJEXT) main.$(OBJEXT) \
+ ppastats.$(OBJEXT)
ppastats_OBJECTS = $(am_ppastats_OBJECTS)
ppastats_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
ppastats_SOURCES = \
cache.h cache.c\
html.h html.c\
+ list.h list.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
main.c\
- ppastats.h
+ ppastats.h ppastats.c
dist_man_MANS = ppastats.1
all: all-am
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cache.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_json.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_ws.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppastats.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
02110-1301 USA
*/
+#include <string.h>
+
#include "cache.h"
#include "ppastats.h"
#include <stdlib.h>
#include <stdio.h>
-#include <string.h>
/*
- Stupid cache implementation but should be enough for storing LP data.
+ Simple cache implementation but should be enough for storing LP data.
*/
struct entry {
#include <string.h>
#include "html.h"
+#include "list.h"
#include "lp_ws.h"
#include <json/json.h>
#define HTML_TEMPLATE \
"<html>\n\
<head>\n\
- <script type='text/javascript' src='https://www.google.com/jsapi'></script>\n\
+ <script type='text/javascript'\
+ src='https://www.google.com/jsapi'></script>\n\
<script type='text/javascript'>\n\
google.load('visualization', '1', {packages:['corechart']});\
google.setOnLoadCallback(drawChart);\n\
%s\
data.addRows(%s);\n\
data.sort(0);\n\
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));\n\
- chart.draw(data, {width: 1024, height: 768, title: 'PPA Statistics'});\n\
+ var chart = new google.visualization.LineChart\
+ (document.getElementById('chart_div'));\n\
+ chart.draw(data, {width: 1024, height: 768,\
+ title: 'PPA Statistics'});\n\
}\n\
</script>\n\
</head>\n\
--- /dev/null
+/*
+ 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
+*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "list.h"
+
+int list_length(void **list)
+{
+ int n;
+
+ n = 0;
+ while (list && *list) {
+ list++;
+ n++;
+ }
+
+ return n;
+}
+
+void **list_add(void **list, void *new_item)
+{
+ int n;
+ void **new_list;
+
+ n = list_length(list);
+
+ new_list = malloc(sizeof(void *)*(n+2));
+
+ if (n)
+ memcpy(new_list, list, sizeof(void *)*n);
+
+ new_list[n] = new_item;
+ new_list[n+1] = NULL;
+
+ free(list);
+
+ return new_list;
+}
+
--- /dev/null
+/*
+ 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
+*/
+
+#ifndef _PPASTATS_LIST_H_
+#define _PPASTATS_LIST_H_
+
+int list_length(void **list);
+void **list_add(void **list, void *new_item);
+
+#endif
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include "lp.h"
}
void
-binary_package_publishing_history_free(struct binary_package_publishing_history *b)
+binary_package_publishing_history_free \
+(struct binary_package_publishing_history *b)
{
if (b) {
free(b->binary_package_name);
}
void
-binary_package_publishing_history_list_free(struct binary_package_publishing_history **list)
+binary_package_publishing_history_list_free\
+(struct binary_package_publishing_history **list)
{
struct binary_package_publishing_history **l_cur = list;
}
}
-int list_length(void **list)
-{
- int n;
-
- n = 0;
- while (*list) {
- list++;
- n++;
- }
-
- return n;
-}
-
char *get_archive_url(const char *owner, const char *ppa);
-int list_length(void **list);
-
#endif
static void display_published_binaries(const char *owner, const char *ppa)
{
- struct binary_package_publishing_history **e_cur, **list;
- char *archive_url = get_archive_url(owner, ppa);
+ struct ppa_stats *ppastats;
+ struct package_stats **packages;
+ struct version_stats **versions;
+ struct distro_stats **distros;
+ struct arch_stats **archs;
- list = get_binary_package_publishing_history_list(archive_url);
- free(archive_url);
+ ppastats = create_ppa_stats(owner, ppa);
+ packages = ppastats->packages;
+ while (packages && *packages) {
+ struct package_stats *p = *packages;
- if (!list) {
- fprintf(stderr, "Failed to retrieve PPA information\n");
- exit(EXIT_FAILURE);
- }
+ printf("%s (%d)\n", p->name, p->download_count);
+
+ versions = p->versions;
+
+ while (*versions) {
+ printf("\t%s (%d)\n", (*versions)->version,
+ (*versions)->download_count);
+
+ distros = (*versions)->distros;
+
+ while (*distros) {
+ printf("\t\t%s (%d)\n",
+ (*distros)->name,
+ (*distros)->download_count);
+
+ archs = (*distros)->archs;
+
+ while (*archs) {
+ printf("\t\t\t%s (%d)\n",
+ (*archs)->name,
+ (*archs)->download_count);
+
+ archs++;
+ }
+
+ distros++;
+ }
+
+ versions++;
+ }
- e_cur = list;
- while (*e_cur) {
- struct binary_package_publishing_history *binary;
- const struct distro_arch_series *arch;
- const struct distro_series *distro;
-
- binary = *e_cur;
- arch = get_distro_arch_series(binary->distro_arch_series_link);
- distro = get_distro_series(arch->distroseries_link);
-
- printf("%s %s %s(%s): %d\n",
- binary->binary_package_name,
- binary->binary_package_version,
- distro->name,
- arch->architecture_tag,
- get_download_count(binary->self_link));
- e_cur++;
+ packages++;
}
- binary_package_publishing_history_list_free(list);
+ ppa_stats_free(ppastats);
}
static struct option long_options[] = {
--- /dev/null
+/*
+ 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
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "list.h"
+#include "lp_ws.h"
+#include "ppastats.h"
+
+static struct package_stats *get_package_stats(struct ppa_stats *stats,
+ const char *name)
+
+{
+ struct package_stats *p, **p_cur;
+
+ p_cur = stats->packages;
+ while (p_cur && *p_cur) {
+ struct package_stats *p = *p_cur;
+
+ if (!strcmp(p->name, name))
+ return p;
+
+ p_cur++;
+ }
+
+ p = malloc(sizeof(struct package_stats));
+ p->name = strdup(name);
+ p->versions = NULL;
+ p->download_count = 0;
+ p->daily_download_totals = NULL;
+
+ stats->packages = (struct package_stats **)list_add
+ ((void **)stats->packages, p);
+
+ return p;
+}
+
+static struct version_stats *get_version_stats(struct package_stats *package,
+ const char *version)
+{
+ struct version_stats *v, **cur;
+
+ cur = package->versions;
+ while (cur && *cur) {
+ struct version_stats *v = *cur;
+
+ if (!strcmp(v->version, version))
+ return v;
+
+ cur++;
+ }
+
+ v = malloc(sizeof(struct version_stats));
+ v->version = strdup(version);
+ v->distros = NULL;
+ v->download_count = 0;
+ v->daily_download_totals = NULL;
+
+ package->versions
+ = (struct version_stats **)list_add((void **)package->versions,
+ v);
+
+ return v;
+}
+
+static struct distro_stats *get_distro_stats(struct version_stats *version,
+ const char *name)
+{
+ struct distro_stats **cur = version->distros;
+ struct distro_stats *d;
+
+ while (cur && *cur) {
+ d = *cur;
+
+ if (!strcmp(d->name, name))
+ return d;
+
+ cur++;
+ }
+
+ d = malloc(sizeof(struct distro_stats));
+ d->name = strdup(name);
+ d->archs = NULL;
+ d->download_count = 0;
+ d->daily_download_totals = NULL;
+
+ version->distros
+ = (struct distro_stats **)list_add((void **)version->distros,
+ d);
+
+ return d;
+}
+
+static struct arch_stats *get_arch_stats(struct distro_stats *distro,
+ const char *name)
+{
+ struct arch_stats **cur = distro->archs;
+ struct arch_stats *a;
+
+ while (cur && *cur) {
+ a = *cur;
+
+ if (!strcmp(a->name, name))
+ return a;
+
+ cur++;
+ }
+
+ a = malloc(sizeof(struct arch_stats));
+ a->name = strdup(name);
+ a->daily_download_totals = NULL;
+ a->download_count = 0;
+
+ distro->archs
+ = (struct arch_stats **)list_add((void **)distro->archs,
+ a);
+
+ return a;
+}
+
+
+struct ppa_stats *create_ppa_stats(const char *owner, const char *ppa)
+{
+ struct ppa_stats *ppastats;
+ struct binary_package_publishing_history **history;
+ struct binary_package_publishing_history **h_cur;
+ struct binary_package_publishing_history *h;
+ char *ppa_url, *package_name, *package_version;
+ struct package_stats *package;
+ struct version_stats *version;
+ const struct distro_series *distro_series;
+ const struct distro_arch_series *arch_series;
+ struct distro_stats *distro;
+ struct arch_stats *arch;
+ int count;
+
+ ppa_url = get_archive_url(owner, ppa);
+ history = get_binary_package_publishing_history_list(ppa_url);
+ free(ppa_url);
+
+ if (!history) {
+ fprintf(stderr, "Failed to retrieve PPA information\n");
+ exit(EXIT_FAILURE);
+ }
+
+ ppastats = malloc(sizeof(struct ppa_stats));
+ ppastats->name = strdup(ppa);
+ ppastats->owner = strdup(owner);
+ ppastats->packages = NULL;
+ ppastats->daily_download_totals = NULL;
+ ppastats->download_count = 0;
+
+ h_cur = history;
+ while (*h_cur) {
+ h = *h_cur;
+ package_name = h->binary_package_name;
+ package_version = h->binary_package_version;
+ arch_series
+ = get_distro_arch_series(h->distro_arch_series_link);
+ distro_series
+ = get_distro_series(arch_series->distroseries_link);
+ count = get_download_count(h->self_link);
+
+ package = get_package_stats(ppastats, package_name);
+ package->download_count += count;
+
+ version = get_version_stats(package, package_version);
+ version->download_count += count;
+
+ distro = get_distro_stats(version, distro_series->name);
+ distro->download_count += count;
+
+ arch = get_arch_stats(distro, arch_series->architecture_tag);
+ arch->download_count += count;
+
+ ppastats->download_count += count;
+
+ h_cur++;
+ }
+
+ binary_package_publishing_history_list_free(history);
+
+ return ppastats;
+}
+
+static void arch_stats_free(struct arch_stats *arch)
+{
+ free(arch->name);
+ free(arch);
+}
+
+static void distro_stats_free(struct distro_stats *distro)
+{
+ struct arch_stats **archs;
+
+ archs = distro->archs;
+ if (archs) {
+ while (*archs) {
+ arch_stats_free(*archs);
+ archs++;
+ }
+ free(distro->archs);
+ }
+
+ free(distro->name);
+ free(distro);
+}
+
+static void version_stats_free(struct version_stats *version)
+{
+ struct distro_stats **distros;
+
+ distros = version->distros;
+ if (distros) {
+ while (*distros) {
+ distro_stats_free(*distros);
+ distros++;
+ }
+ free(version->distros);
+ }
+
+ free(version->version);
+ free(version);
+}
+
+static void package_stats_free(struct package_stats *package)
+{
+ struct version_stats **versions;
+
+ versions = package->versions;
+ if (versions) {
+ while (*versions) {
+ version_stats_free(*versions);
+ versions++;
+ }
+ free(package->versions);
+ }
+
+ free(package->name);
+ free(package);
+}
+
+void ppa_stats_free(struct ppa_stats *ppastats)
+{
+ struct package_stats **packages;
+
+ packages = ppastats->packages;
+ if (packages) {
+ while (*packages) {
+ package_stats_free(*packages);
+ packages++;
+ }
+ free(ppastats->packages);
+ }
+
+ free(ppastats->owner);
+ free(ppastats->name);
+
+ free(ppastats);
+}
extern int debug;
+#include "lp.h"
+
+struct arch_stats {
+ char *name;
+
+ struct daily_download_total *daily_download_totals;
+ int download_count;
+};
+
+struct distro_stats {
+ char *name;
+
+ struct arch_stats **archs;
+ int download_count;
+ struct daily_download_total *daily_download_totals;
+};
+
+struct version_stats {
+ char *version;
+
+ struct distro_stats **distros;
+ int download_count;
+ struct daily_download_total *daily_download_totals;
+};
+
+struct package_stats {
+ char *name;
+
+ struct version_stats **versions;
+ int download_count;
+ struct daily_download_total *daily_download_totals;
+};
+
+struct ppa_stats {
+ char *name;
+ char *owner;
+
+ struct package_stats **packages;
+ int download_count;
+ struct daily_download_total *daily_download_totals;
+};
+
+struct ppa_stats *create_ppa_stats(const char *owner, const char *ppa);
+void ppa_stats_free(struct ppa_stats *ppastats);
+
#endif