X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fmain.c;h=b590c67169ac52511ddbd110d829b84a01565079;hb=0303d0d705cfc2a100403a708fca0e93b12d2a93;hp=0df293d9dde95ea4fd855f4525666ec732fef315;hpb=4465dc507c2b2ea1fcd3902f167cd3d51b21fdc8;p=ppastats.git diff --git a/src/main.c b/src/main.c index 0df293d..b590c67 100644 --- a/src/main.c +++ b/src/main.c @@ -1,127 +1,183 @@ -/*a - 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-2014 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 +#define _(String) gettext(String) #include #include #include #include +#include "cache.h" +#include #include "html.h" +#include "http.h" #include "lp_ws.h" #include "config.h" +#include +#include "ppastats.h" 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, + int ws_size) { - 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, ws_size); + 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; - e_cur = list; - while (*e_cur) { - struct binary_package_publishing_history *binary; - struct distro_arch_series *dist; + while (*versions) { + printf("\t%s (%d)\n", (*versions)->version, + (*versions)->download_count); - binary = *e_cur; - dist = get_distro_arch_series(binary->distro_arch_series_link); + distros = (*versions)->distros; - printf("%s %s %s %d\n", - dist->display_name, - binary->binary_package_name, - binary->binary_package_version, - get_download_count(binary->self_link)); - e_cur++; + 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++; + } + + 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'}, + {"get-bpph-size", required_argument, 0, 0}, {0, 0, 0, 0} }; static void print_version() { printf("ppastats %s\n", VERSION); - 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"); + printf(_("Copyright (C) %s jeanfi@gmail.com\n" +"License GPLv2: GNU GPL version 2 or later\n" +"\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"), + "2011-2014"); } static void print_help() { - printf("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n", program_name); - - puts("ppastats is a command application" - " for generating PPA statistics.\n"); + printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name); - puts("Prints number of downloads for each published packages of a PPA " - "or generates an HTML page containing a graph representation."); + puts(_( +"ppastats is a command application for generating PPA statistics.\n")); + puts(_( +"Prints number of downloads for each published packages of a PPA or generates\n" +"an HTML page containing a graph representation.")); puts(""); - puts("Options:"); - puts("\ - -h, --help display this help and exit\n\ - -v, --version display version information and exit"); + puts(_("Options:")); + puts(_(" -h, --help display this help and exit")); + puts(_(" -v, --version display version information and exit")); puts(""); - puts("\ - -t, --html \ -generates an HTML output."); + puts(_(" -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(_( +" --get-bpph-size=[s] size of the replies of webservice requests to get\n" +" the list of binary packages. Between 1 and 300.")); puts(""); - printf("Report bugs to: %s\n", PACKAGE_BUGREPORT); + printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT); puts(""); - printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); + printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); } - int main(int argc, char **argv) { - char *owner, *ppa; - int optc; - int output_html = 0; - int cmdok = 1; + char *owner, *ppa, *package_status, *output_dir; + int optc, output_html, cmdok, install_static_files, ws_size, opti; program_name = argv[0]; - while ((optc = getopt_long(argc, argv, "vht", long_options, - NULL)) != -1) { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + cmdok = 1; + install_static_files = 1; + output_dir = NULL; + package_status = NULL; + output_html = 0; + ws_size = -1; + + while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options, + &opti)) != -1) { switch (optc) { - case 't': + case 0: + if (!strcmp(long_options[opti].name, "get-bpph-size")) + ws_size = atoi(optarg); + break; + case 'o': output_html = 1; + output_dir = strdup(optarg); + break; + case 'd': + log_level = LOG_DEBUG; break; case 'h': print_help(); @@ -129,6 +185,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; @@ -136,18 +199,34 @@ int main(int argc, char **argv) } if (!cmdok || optind + 2 != argc) { - fprintf(stderr, "Try `%s --help' for more information.\n", + fprintf(stderr, + _("Try `%s --help' for more information.\n"), program_name); exit(EXIT_FAILURE); } + log_open("ppastats.log"); + owner = argv[optind]; ppa = argv[optind+1]; if (output_html) - ppa_to_html(owner, ppa); + ppa_to_html(owner, + ppa, + package_status, + output_dir, + install_static_files, + ws_size); else - display_published_binaries(owner, ppa); + display_published_binaries(owner, ppa, package_status, ws_size); + + /* for valgrind.... */ + free(package_status); + free(output_dir); + http_cleanup(); + cache_cleanup(); + fcache_cleanup(); + html_cleanup(); exit(EXIT_SUCCESS); }