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)
35 static const char *program_name;
37 static void display_published_binaries(const char *owner,
39 const char *package_status)
41 struct ppa_stats *ppastats;
42 struct package_stats **packages;
43 struct version_stats **versions;
44 struct distro_stats **distros;
45 struct arch_stats **archs;
47 ppastats = create_ppa_stats(owner, ppa, package_status);
48 packages = ppastats->packages;
49 while (packages && *packages) {
50 struct package_stats *p = *packages;
52 printf("%s (%d)\n", p->name, p->download_count);
54 versions = p->versions;
57 printf("\t%s (%d)\n", (*versions)->version,
58 (*versions)->download_count);
60 distros = (*versions)->distros;
63 printf("\t\t%s (%d)\n",
65 (*distros)->download_count);
67 archs = (*distros)->archs;
70 printf("\t\t\t%s (%d)\n",
72 (*archs)->download_count);
86 ppa_stats_free(ppastats);
89 static struct option long_options[] = {
90 {"version", no_argument, 0, 'v'},
91 {"help", no_argument, 0, 'h'},
92 {"output-dir", required_argument, 0, 'o'},
93 {"debug", no_argument, 0, 'd'},
94 {"status", required_argument, 0, 's'},
95 {"skip-js-css", no_argument, 0, 'S'},
99 static void print_version()
101 printf("ppastats %s\n", VERSION);
102 printf(_("Copyright (C) %s jeanfi@gmail.com\n\
103 License GPLv2: GNU GPL version 2 or later \
104 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
105 This is free software: you are free to change and redistribute it.\n\
106 There is NO WARRANTY, to the extent permitted by law.\n"),
110 static void print_help()
112 printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name);
114 puts(_("ppastats is a command application"
115 " for generating PPA statistics.\n"));
117 puts(_("Prints number of downloads for each published packages of a "
118 "PPA or generates an HTML page containing a graph "
124 -h, --help display this help and exit\n\
125 -v, --version display version information and exit"));
130 -o, --output-dir=[PATH] generates HTML pages into 'PATH'."));
133 -s, --status=[STATUS] retrieves only package of the given status\n\
134 (possible values are: Pending, Published, \n\
135 Superseded, Deleted or Obsolete)."));
138 -S, --skip-js-css skip installation of js and css files"));
141 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
143 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
146 int main(int argc, char **argv)
148 char *owner, *ppa, *package_status, *output_dir;
149 int optc, output_html, cmdok, install_static_files;
151 program_name = argv[0];
153 setlocale(LC_ALL, "");
154 bindtextdomain(PACKAGE, LOCALEDIR);
158 install_static_files = 1;
160 package_status = NULL;
163 while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options,
168 output_dir = strdup(optarg);
181 package_status = strdup(optarg);
184 install_static_files = 0;
192 if (!cmdok || optind + 2 != argc) {
193 fprintf(stderr, _("Try `%s --help' for more information.\n"),
198 owner = argv[optind];
199 ppa = argv[optind+1];
202 ppa_to_html(owner, ppa, package_status, output_dir,
203 install_static_files);
205 display_published_binaries(owner, ppa, package_status);
207 /* for valgrind.... */
208 free(package_status);