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
32 static const char *program_name;
34 static void display_published_binaries(const char *owner,
36 const char *package_status)
38 struct ppa_stats *ppastats;
39 struct package_stats **packages;
40 struct version_stats **versions;
41 struct distro_stats **distros;
42 struct arch_stats **archs;
44 ppastats = create_ppa_stats(owner, ppa, package_status);
45 packages = ppastats->packages;
46 while (packages && *packages) {
47 struct package_stats *p = *packages;
49 printf("%s (%d)\n", p->name, p->download_count);
51 versions = p->versions;
54 printf("\t%s (%d)\n", (*versions)->version,
55 (*versions)->download_count);
57 distros = (*versions)->distros;
60 printf("\t\t%s (%d)\n",
62 (*distros)->download_count);
64 archs = (*distros)->archs;
67 printf("\t\t\t%s (%d)\n",
69 (*archs)->download_count);
83 ppa_stats_free(ppastats);
86 static struct option long_options[] = {
87 {"version", no_argument, 0, 'v'},
88 {"help", no_argument, 0, 'h'},
89 {"output-dir", required_argument, 0, 'o'},
90 {"debug", no_argument, 0, 'd'},
91 {"status", required_argument, 0, 's'},
92 {"skip-js-css", no_argument, 0, 'S'},
96 static void print_version()
98 printf("ppastats %s\n", VERSION);
99 printf("Copyright (C) %s jeanfi@gmail.com\n\
100 License GPLv2: GNU GPL version 2 or later \
101 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
102 This is free software: you are free to change and redistribute it.\n\
103 There is NO WARRANTY, to the extent permitted by law.\n",
107 static void print_help()
109 printf("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n", program_name);
111 puts("ppastats is a command application"
112 " for generating PPA statistics.\n");
114 puts("Prints number of downloads for each published packages of a PPA "
115 "or generates an HTML page containing a graph representation.");
120 -h, --help display this help and exit\n\
121 -v, --version display version information and exit");
126 -o, --output-dir=[PATH] \
127 generates HTML pages into 'PATH'.");
130 -s, --status=[STATUS] retrieves only package of the given status\n\
131 (possible values are: Pending, Published, \n\
132 Superseded, Deleted or Obsolete).");
135 -S, --skip-js-css skip installation of js and css files");
138 printf("Report bugs to: %s\n", PACKAGE_BUGREPORT);
140 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
144 int main(int argc, char **argv)
149 char *package_status = NULL;
151 char *output_dir = NULL;
152 int install_static_files = 1;
154 program_name = argv[0];
156 while ((optc = getopt_long(argc, argv, "vho:ds:S", long_options,
161 output_dir = strdup(optarg);
174 package_status = strdup(optarg);
177 install_static_files = 0;
185 if (!cmdok || optind + 2 != argc) {
186 fprintf(stderr, "Try `%s --help' for more information.\n",
191 owner = argv[optind];
192 ppa = argv[optind+1];
195 ppa_to_html(owner, ppa, package_status, output_dir,
196 install_static_files);
198 display_published_binaries(owner, ppa, package_status);
200 /* for valgrind.... */
201 free(package_status);