X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fmain.c;h=0b193b468f2520f91748942f75f10ef385cd4a78;hb=533275304146eb804504e5885ce003f9f066fc20;hp=02861eacc288059a5bda53029e0a3e25b28e5e37;hpb=f2b0384f6231324f53e78aa458b9a46b0e659c43;p=ppastats.git diff --git a/src/main.c b/src/main.c index 02861ea..0b193b4 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#define _(String) gettext (String) #include #include @@ -31,63 +33,82 @@ int debug; static const char *program_name; -static void display_published_binaries(const char *owner, const char *ppa) +static void display_published_binaries(const char *owner, + const char *ppa, + const char *package_status) { - 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, package_status); + 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++; + } - 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++; + versions++; + } + + packages++; } - binary_package_publishing_history_list_free(list); + ppa_stats_free(ppastats); } static struct option long_options[] = { {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, - {"html", no_argument, 0, 't'}, + {"output-dir", required_argument, 0, 'o'}, {"debug", no_argument, 0, 'd'}, + {"status", required_argument, 0, 's'}, + {"skip-js-css", no_argument, 0, 'S'}, {0, 0, 0, 0} }; static void print_version() { printf("ppastats %s\n", VERSION); - printf("Copyright (C) %s jeanfi@gmail.com\n\ + printf(_("Copyright (C) %s jeanfi@gmail.com\n\ License GPLv2: GNU GPL version 2 or later \ \n\ This is free software: you are free to change and redistribute it.\n\ -There is NO WARRANTY, to the extent permitted by law.\n", - "2010-2011"); +There is NO WARRANTY, to the extent permitted by law.\n"), + "2011-2012"); } static void print_help() { - printf("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n", program_name); + printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name); puts("ppastats is a command application" " for generating PPA statistics.\n"); @@ -96,17 +117,24 @@ static void print_help() "or generates an HTML page containing a graph representation."); puts(""); - puts("Options:"); - puts("\ + puts(_("Options:")); + puts(_("\ -h, --help display this help and exit\n\ - -v, --version display version information and exit"); + -v, --version display version information and exit")); puts(""); puts("\ - -t, --html \ -generates an HTML output."); + -o, --output-dir=[PATH] \ +generates HTML pages into 'PATH'."); + + puts("\ + -s, --status=[STATUS] retrieves only package of the given status\n\ + (possible values are: Pending, Published, \n\ + Superseded, Deleted or Obsolete)."); + puts("\ + -S, --skip-js-css skip installation of js and css files"); puts(""); printf("Report bugs to: %s\n", PACKAGE_BUGREPORT); @@ -120,15 +148,23 @@ int main(int argc, char **argv) char *owner, *ppa; int optc; int output_html = 0; + char *package_status = NULL; int cmdok = 1; + char *output_dir = NULL; + int install_static_files = 1; program_name = argv[0]; - while ((optc = getopt_long(argc, argv, "vhtd", long_options, + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options, NULL)) != -1) { switch (optc) { - case 't': + case 'o': output_html = 1; + output_dir = strdup(optarg); break; case 'd': debug = 1; @@ -139,6 +175,13 @@ int main(int argc, char **argv) case 'v': print_version(); exit(EXIT_SUCCESS); + case 's': + if (optarg) + package_status = strdup(optarg); + break; + case 'S': + install_static_files = 0; + break; default: cmdok = 0; break; @@ -155,11 +198,14 @@ int main(int argc, char **argv) ppa = argv[optind+1]; if (output_html) - ppa_to_html(owner, ppa); + ppa_to_html(owner, ppa, package_status, output_dir, + install_static_files); else - display_published_binaries(owner, ppa); + display_published_binaries(owner, ppa, package_status); /* for valgrind.... */ + free(package_status); + free(output_dir); lp_ws_cleanup(); cache_cleanup();