2 Copyright (C) 2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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
20 #define _(String) gettext (String)
34 static const char *program_name;
36 static void display_published_binaries(const char *owner,
38 const char *package_status)
40 struct ppa_stats *ppastats;
41 struct package_stats **packages;
42 struct version_stats **versions;
43 struct distro_stats **distros;
44 struct arch_stats **archs;
46 ppastats = create_ppa_stats(owner, ppa, package_status);
47 packages = ppastats->packages;
48 while (packages && *packages) {
49 struct package_stats *p = *packages;
51 printf("%s (%d)\n", p->name, p->download_count);
53 versions = p->versions;
56 printf("\t%s (%d)\n", (*versions)->version,
57 (*versions)->download_count);
59 distros = (*versions)->distros;
62 printf("\t\t%s (%d)\n",
64 (*distros)->download_count);
66 archs = (*distros)->archs;
69 printf("\t\t\t%s (%d)\n",
71 (*archs)->download_count);
85 ppa_stats_free(ppastats);
88 static struct option long_options[] = {
89 {"version", no_argument, 0, 'v'},
90 {"help", no_argument, 0, 'h'},
91 {"output-dir", required_argument, 0, 'o'},
92 {"debug", no_argument, 0, 'd'},
93 {"status", required_argument, 0, 's'},
94 {"skip-js-css", no_argument, 0, 'S'},
98 static void print_version()
100 printf("ppastats %s\n", VERSION);
101 printf(_("Copyright (C) %s jeanfi@gmail.com\n\
102 License GPLv2: GNU GPL version 2 or later \
103 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
104 This is free software: you are free to change and redistribute it.\n\
105 There is NO WARRANTY, to the extent permitted by law.\n"),
109 static void print_help()
111 printf(_("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"), program_name);
113 puts("ppastats is a command application"
114 " for generating PPA statistics.\n");
116 puts("Prints number of downloads for each published packages of a PPA "
117 "or generates an HTML page containing a graph representation.");
122 -h, --help display this help and exit\n\
123 -v, --version display version information and exit"));
128 -o, --output-dir=[PATH] \
129 generates HTML pages into 'PATH'.");
132 -s, --status=[STATUS] retrieves only package of the given status\n\
133 (possible values are: Pending, Published, \n\
134 Superseded, Deleted or Obsolete).");
137 -S, --skip-js-css skip installation of js and css files");
140 printf("Report bugs to: %s\n", PACKAGE_BUGREPORT);
142 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
146 int main(int argc, char **argv)
151 char *package_status = NULL;
153 char *output_dir = NULL;
154 int install_static_files = 1;
156 program_name = argv[0];
158 setlocale(LC_ALL, "");
159 bindtextdomain(PACKAGE, LOCALEDIR);
162 while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options,
167 output_dir = strdup(optarg);
180 package_status = strdup(optarg);
183 install_static_files = 0;
191 if (!cmdok || optind + 2 != argc) {
192 fprintf(stderr, "Try `%s --help' for more information.\n",
197 owner = argv[optind];
198 ppa = argv[optind+1];
201 ppa_to_html(owner, ppa, package_status, output_dir,
202 install_static_files);
204 display_published_binaries(owner, ppa, package_status);
206 /* for valgrind.... */
207 free(package_status);