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)
38 static const char *program_name;
40 static void display_published_binaries(const char *owner,
42 const char *package_status,
45 struct ppa_stats *ppastats;
46 struct package_stats **packages;
47 struct version_stats **versions;
48 struct distro_stats **distros;
49 struct arch_stats **archs;
51 ppastats = create_ppa_stats(owner, ppa, package_status, ws_size);
52 packages = ppastats->packages;
53 while (packages && *packages) {
54 struct package_stats *p = *packages;
56 printf("%s (%d)\n", p->name, p->download_count);
58 versions = p->versions;
61 printf("\t%s (%d)\n", (*versions)->version,
62 (*versions)->download_count);
64 distros = (*versions)->distros;
67 printf("\t\t%s (%d)\n",
69 (*distros)->download_count);
71 archs = (*distros)->archs;
74 printf("\t\t\t%s (%d)\n",
76 (*archs)->download_count);
90 ppa_stats_free(ppastats);
93 static struct option long_options[] = {
94 {"version", no_argument, 0, 'v'},
95 {"help", no_argument, 0, 'h'},
96 {"output-dir", required_argument, 0, 'o'},
97 {"debug", no_argument, 0, 'd'},
98 {"status", required_argument, 0, 's'},
99 {"skip-js-css", no_argument, 0, 'S'},
100 {"get-bpph-size", required_argument, 0, 0},
101 {"theme-dir", required_argument, 0, 't'},
105 static void print_version()
107 printf("ppastats %s\n", VERSION);
108 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
109 "License GPLv2: GNU GPL version 2 or later\n"
110 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
111 "This is free software: you are free to change and redistribute it.\n"
112 "There is NO WARRANTY, to the extent permitted by law.\n"),
116 static void print_help()
118 printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name);
121 "ppastats is a command application for generating PPA statistics.\n"));
123 "Prints number of downloads for each published packages of a PPA or generates\n"
124 "an HTML page containing a graph representation."));
128 puts(_(" -h, --help display this help and exit"));
129 puts(_(" -v, --version display version information and exit"));
133 puts(_(" -o, --output-dir=[PATH] generates HTML pages into 'PATH'"));
134 puts(_(" -t, --theme-dir=[PATH] set theme dir to 'PATH'"));
137 " -s, --status=[STATUS] retrieves only package of the given status\n"
138 " (possible values are: Pending, Published,\n"
139 " Superseded, Deleted or Obsolete)"));
142 " -S, --skip-js-css skip installation of js and css files"));
144 " --get-bpph-size=[s] size of the replies of webservice requests to get\n"
145 " the list of binary packages. Between 1 and 300."));
148 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
150 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
153 int main(int argc, char **argv)
155 char *owner, *ppa, *package_status, *output_dir, *theme_dir, *log, *tmp;
156 int optc, output_html, cmdok, install_static_files, ws_size, opti;
158 program_name = argv[0];
160 setlocale(LC_ALL, "");
161 bindtextdomain(PACKAGE, LOCALEDIR);
165 install_static_files = 1;
167 package_status = NULL;
172 while ((optc = getopt_long(argc, argv, "vho:t:ds:S", long_options,
176 if (!strcmp(long_options[opti].name, "get-bpph-size"))
177 ws_size = atoi(optarg);
181 output_dir = strdup(optarg);
184 log_level = LOG_DEBUG;
194 package_status = strdup(optarg);
198 theme_dir = strdup(optarg);
201 install_static_files = 0;
209 if (!cmdok || optind + 2 != argc) {
211 _("Try `%s --help' for more information.\n"),
216 tmp = path_append(getenv("HOME"), ".ppastats");
217 log = path_append(tmp, "ppastats.log");
222 owner = argv[optind];
223 ppa = argv[optind+1];
227 html_set_theme_dir(theme_dir);
229 html_set_theme_dir(DEFAULT_THEME_DIR);
234 install_static_files,
237 display_published_binaries(owner, ppa, package_status, ws_size);
240 /* for valgrind.... */
241 free(package_status);