2 * Copyright (C) 2011-2014 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)
37 static const char *program_name;
39 static void display_published_binaries(const char *owner,
41 const char *package_status,
44 struct ppa_stats *ppastats;
45 struct package_stats **packages;
46 struct version_stats **versions;
47 struct distro_stats **distros;
48 struct arch_stats **archs;
50 ppastats = create_ppa_stats(owner, ppa, package_status, ws_size);
51 packages = ppastats->packages;
52 while (packages && *packages) {
53 struct package_stats *p = *packages;
55 printf("%s (%d)\n", p->name, p->download_count);
57 versions = p->versions;
60 printf("\t%s (%d)\n", (*versions)->version,
61 (*versions)->download_count);
63 distros = (*versions)->distros;
66 printf("\t\t%s (%d)\n",
68 (*distros)->download_count);
70 archs = (*distros)->archs;
73 printf("\t\t\t%s (%d)\n",
75 (*archs)->download_count);
89 ppa_stats_free(ppastats);
92 static struct option long_options[] = {
93 {"version", no_argument, 0, 'v'},
94 {"help", no_argument, 0, 'h'},
95 {"output-dir", required_argument, 0, 'o'},
96 {"debug", no_argument, 0, 'd'},
97 {"status", required_argument, 0, 's'},
98 {"skip-js-css", no_argument, 0, 'S'},
99 {"get-bpph-size", required_argument, 0, 0},
100 {"theme-dir", required_argument, 0, 't'},
104 static void print_version()
106 printf("ppastats %s\n", VERSION);
107 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
108 "License GPLv2: GNU GPL version 2 or later\n"
109 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
110 "This is free software: you are free to change and redistribute it.\n"
111 "There is NO WARRANTY, to the extent permitted by law.\n"),
115 static void print_help()
117 printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name);
120 "ppastats is a command application for generating PPA statistics.\n"));
122 "Prints number of downloads for each published packages of a PPA or generates\n"
123 "an HTML page containing a graph representation."));
127 puts(_(" -h, --help display this help and exit"));
128 puts(_(" -v, --version display version information and exit"));
132 puts(_(" -o, --output-dir=[PATH] generates HTML pages into 'PATH'"));
133 puts(_(" -t, --theme-dir=[PATH] set theme dir to 'PATH'"));
136 " -s, --status=[STATUS] retrieves only package of the given status\n"
137 " (possible values are: Pending, Published,\n"
138 " Superseded, Deleted or Obsolete)"));
141 " -S, --skip-js-css skip installation of js and css files"));
143 " --get-bpph-size=[s] size of the replies of webservice requests to get\n"
144 " the list of binary packages. Between 1 and 300."));
147 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
149 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
152 int main(int argc, char **argv)
154 char *owner, *ppa, *package_status, *output_dir, *theme_dir;
155 int optc, output_html, cmdok, install_static_files, ws_size, opti;
157 program_name = argv[0];
159 setlocale(LC_ALL, "");
160 bindtextdomain(PACKAGE, LOCALEDIR);
164 install_static_files = 1;
166 package_status = NULL;
171 while ((optc = getopt_long(argc, argv, "vho:t:ds:S", long_options,
175 if (!strcmp(long_options[opti].name, "get-bpph-size"))
176 ws_size = atoi(optarg);
180 output_dir = strdup(optarg);
183 log_level = LOG_DEBUG;
193 package_status = strdup(optarg);
197 theme_dir = strdup(optarg);
200 install_static_files = 0;
208 if (!cmdok || optind + 2 != argc) {
210 _("Try `%s --help' for more information.\n"),
215 log_open("ppastats.log");
217 owner = argv[optind];
218 ppa = argv[optind+1];
222 html_set_theme_dir(theme_dir);
224 html_set_theme_dir(DEFAULT_THEME_DIR);
229 install_static_files,
232 display_published_binaries(owner, ppa, package_status, ws_size);
235 /* for valgrind.... */
236 free(package_status);