2 * Copyright (C) 2011-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #define _(String) gettext(String)
36 static const char *program_name;
38 static void display_published_binaries(const char *owner,
40 const char *package_status)
42 struct ppa_stats *ppastats;
43 struct package_stats **packages;
44 struct version_stats **versions;
45 struct distro_stats **distros;
46 struct arch_stats **archs;
48 ppastats = create_ppa_stats(owner, ppa, package_status);
49 packages = ppastats->packages;
50 while (packages && *packages) {
51 struct package_stats *p = *packages;
53 printf("%s (%d)\n", p->name, p->download_count);
55 versions = p->versions;
58 printf("\t%s (%d)\n", (*versions)->version,
59 (*versions)->download_count);
61 distros = (*versions)->distros;
64 printf("\t\t%s (%d)\n",
66 (*distros)->download_count);
68 archs = (*distros)->archs;
71 printf("\t\t\t%s (%d)\n",
73 (*archs)->download_count);
87 ppa_stats_free(ppastats);
90 static struct option long_options[] = {
91 {"version", no_argument, 0, 'v'},
92 {"help", no_argument, 0, 'h'},
93 {"output-dir", required_argument, 0, 'o'},
94 {"debug", no_argument, 0, 'd'},
95 {"status", required_argument, 0, 's'},
96 {"skip-js-css", no_argument, 0, 'S'},
100 static void print_version()
102 printf("ppastats %s\n", VERSION);
103 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
104 "License GPLv2: GNU GPL version 2 or later\n"
105 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
106 "This is free software: you are free to change and redistribute it.\n"
107 "There is NO WARRANTY, to the extent permitted by law.\n"),
111 static void print_help()
113 printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name);
116 "ppastats is a command application for generating PPA statistics.\n"));
118 "Prints number of downloads for each published packages of a PPA or generates\n"
119 "an HTML page containing a graph representation."));
123 puts(_(" -h, --help display this help and exit"));
124 puts(_(" -v, --version display version information and exit"));
128 puts(_(" -o, --output-dir=[PATH] generates HTML pages into 'PATH'"));
131 " -s, --status=[STATUS] retrieves only package of the given status\n"
132 " (possible values are: Pending, Published,\n"
133 " Superseded, Deleted or Obsolete)"));
136 " -S, --skip-js-css skip installation of js and css files"));
139 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
141 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
144 int main(int argc, char **argv)
146 char *owner, *ppa, *package_status, *output_dir;
147 int optc, output_html, cmdok, install_static_files;
149 program_name = argv[0];
151 setlocale(LC_ALL, "");
152 bindtextdomain(PACKAGE, LOCALEDIR);
156 install_static_files = 1;
158 package_status = NULL;
161 while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options,
166 output_dir = strdup(optarg);
169 log_level = LOG_DEBUG;
179 package_status = strdup(optarg);
182 install_static_files = 0;
190 if (!cmdok || optind + 2 != argc) {
191 fprintf(stderr, _("Try `%s --help' for more information.\n"),
196 owner = argv[optind];
197 ppa = argv[optind+1];
200 ppa_to_html(owner, ppa, package_status, output_dir,
201 install_static_files);
203 display_published_binaries(owner, ppa, package_status);
205 /* for valgrind.... */
206 free(package_status);