$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3)
POTFILES = \
- ../src/main.c
+ ../src/cache.c \
+ ../src/html.c \
+ ../src/log.c \
+ ../src/lp_ws.c \
+ ../src/main.c \
+ ../src/ppastats.c
CATALOGS = fr.gmo
- ../src/main.c
+ ../src/cache.c \
+ ../src/html.c \
+ ../src/log.c \
+ ../src/lp_ws.c \
+ ../src/main.c \
+ ../src/ppastats.c
# List of source files which contain translatable strings.
+src/cache.c
+src/html.c
+src/log.c
+src/lp_ws.c
src/main.c
+src/ppastats.c
msgstr ""
"Project-Id-Version: ppastats 0.0.x\n"
"Report-Msgid-Bugs-To: jeanfi@gmail.com\n"
-"POT-Creation-Date: 2012-05-05 23:52+0200\n"
+"POT-Creation-Date: 2012-05-06 13:01+0200\n"
"PO-Revision-Date: 2012-05-05 23:45+0200\n"
"Last-Translator: <jeanfi@gmail.com>\n"
"Language-Team: French\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-#: src/main.c:101
+#: src/cache.c:57
+#, c-format
+msgid "cache hit %s"
+msgstr ""
+
+#: src/cache.c:62
+#, c-format
+msgid "cache miss %s"
+msgstr ""
+
+#: src/cache.c:71
+msgid "exceed cache capacity"
+msgstr ""
+
+#: src/html.c:392 src/html.c:417
+#, c-format
+msgid "failed to open: %s"
+msgstr ""
+
+#: src/html.c:448 src/html.c:468 src/html.c:481
+#, c-format
+msgid "generating %s"
+msgstr ""
+
+#: src/html.c:544
+#, c-format
+msgid "copying %s %s"
+msgstr ""
+
+#: src/log.c:37
+#, c-format
+msgid "Cannot open log file: %s"
+msgstr ""
+
+#: src/lp_ws.c:71
+#, c-format
+msgid "fetch_url(): %s"
+msgstr ""
+
+#: src/lp_ws.c:74
+msgid "initializing CURL"
+msgstr ""
+
+#: src/lp_ws.c:109
+#, c-format
+msgid "Fetch failed with code %ld for URL %s"
+msgstr ""
+
+#: src/lp_ws.c:114
+msgid "Wait 5s before retry"
+msgstr ""
+
+#: src/lp_ws.c:122
+#, c-format
+msgid "Fetch failed: %ld"
+msgstr ""
+
+#: src/lp_ws.c:294
+msgid "cleanup CURL"
+msgstr ""
+
+#: src/main.c:102
#, c-format
msgid ""
"Copyright (C) %s jeanfi@gmail.com\n"
"Ce logiciel n'est accompagné d’ABSOLUMENT AUCUNE GARANTIE, dans les limites\n"
"autorisées par la loi applicable.\n"
-#: src/main.c:111
+#: src/main.c:112
#, c-format
msgid "Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"
msgstr "Utilisation: %s [OPTION]... PPA_OWNER PPA_NAME\n"
-#: src/main.c:120
+#: src/main.c:114
+msgid "ppastats is a command application for generating PPA statistics.\n"
+msgstr ""
+
+#: src/main.c:117
+msgid ""
+"Prints number of downloads for each published packages of a PPA or generates "
+"an HTML page containing a graph representation."
+msgstr ""
+
+#: src/main.c:122
msgid "Options:"
msgstr "Options:"
-#: src/main.c:121
+#: src/main.c:123
msgid ""
" -h, --help display this help and exit\n"
" -v, --version display version information and exit"
msgstr ""
" -h, --help afficher cette aide et quitter\n"
" -v, --version afficher les informations de version et quitter"
+
+#: src/main.c:129
+msgid " -o, --output-dir=[PATH] generates HTML pages into 'PATH'."
+msgstr ""
+
+#: src/main.c:132
+msgid ""
+" -s, --status=[STATUS]\t\tretrieves only package of the given status\n"
+"\t\t\t\t(possible values are: Pending, Published, \n"
+"\t\t\t\tSuperseded, Deleted or Obsolete)."
+msgstr ""
+
+#: src/main.c:137
+msgid " -S, --skip-js-css\t\tskip installation of js and css files"
+msgstr ""
+
+#: src/main.c:141
+#, c-format
+msgid "Report bugs to: %s\n"
+msgstr ""
+
+#: src/main.c:143
+#, c-format
+msgid "%s home page: <%s>\n"
+msgstr ""
+
+#: src/main.c:193
+#, c-format
+msgid "Try `%s --help' for more information.\n"
+msgstr ""
+
+#: src/ppastats.c:254
+msgid "Failed to retrieve PPA information"
+msgstr ""
+
+#: src/ppastats.c:269
+#, c-format
+msgid "Failed to retrieve download totals for %s"
+msgstr ""
+
+#: src/ppastats.c:275
+#, c-format
+msgid "Failed to retrieve download count for %s"
+msgstr ""
msgstr ""
"Project-Id-Version: ppastats 0.0.x\n"
"Report-Msgid-Bugs-To: jeanfi@gmail.com\n"
-"POT-Creation-Date: 2012-05-05 23:52+0200\n"
+"POT-Creation-Date: 2012-05-06 13:01+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: src/main.c:101
+#: src/cache.c:57
+#, c-format
+msgid "cache hit %s"
+msgstr ""
+
+#: src/cache.c:62
+#, c-format
+msgid "cache miss %s"
+msgstr ""
+
+#: src/cache.c:71
+msgid "exceed cache capacity"
+msgstr ""
+
+#: src/html.c:392 src/html.c:417
+#, c-format
+msgid "failed to open: %s"
+msgstr ""
+
+#: src/html.c:448 src/html.c:468 src/html.c:481
+#, c-format
+msgid "generating %s"
+msgstr ""
+
+#: src/html.c:544
+#, c-format
+msgid "copying %s %s"
+msgstr ""
+
+#: src/log.c:37
+#, c-format
+msgid "Cannot open log file: %s"
+msgstr ""
+
+#: src/lp_ws.c:71
+#, c-format
+msgid "fetch_url(): %s"
+msgstr ""
+
+#: src/lp_ws.c:74
+msgid "initializing CURL"
+msgstr ""
+
+#: src/lp_ws.c:109
+#, c-format
+msgid "Fetch failed with code %ld for URL %s"
+msgstr ""
+
+#: src/lp_ws.c:114
+msgid "Wait 5s before retry"
+msgstr ""
+
+#: src/lp_ws.c:122
+#, c-format
+msgid "Fetch failed: %ld"
+msgstr ""
+
+#: src/lp_ws.c:294
+msgid "cleanup CURL"
+msgstr ""
+
+#: src/main.c:102
#, c-format
msgid ""
"Copyright (C) %s jeanfi@gmail.com\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
msgstr ""
-#: src/main.c:111
+#: src/main.c:112
#, c-format
msgid "Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n"
msgstr ""
-#: src/main.c:120
+#: src/main.c:114
+msgid "ppastats is a command application for generating PPA statistics.\n"
+msgstr ""
+
+#: src/main.c:117
+msgid ""
+"Prints number of downloads for each published packages of a PPA or generates "
+"an HTML page containing a graph representation."
+msgstr ""
+
+#: src/main.c:122
msgid "Options:"
msgstr ""
-#: src/main.c:121
+#: src/main.c:123
msgid ""
" -h, --help display this help and exit\n"
" -v, --version display version information and exit"
msgstr ""
+
+#: src/main.c:129
+msgid " -o, --output-dir=[PATH] generates HTML pages into 'PATH'."
+msgstr ""
+
+#: src/main.c:132
+msgid ""
+" -s, --status=[STATUS]\t\tretrieves only package of the given status\n"
+"\t\t\t\t(possible values are: Pending, Published, \n"
+"\t\t\t\tSuperseded, Deleted or Obsolete)."
+msgstr ""
+
+#: src/main.c:137
+msgid " -S, --skip-js-css\t\tskip installation of js and css files"
+msgstr ""
+
+#: src/main.c:141
+#, c-format
+msgid "Report bugs to: %s\n"
+msgstr ""
+
+#: src/main.c:143
+#, c-format
+msgid "%s home page: <%s>\n"
+msgstr ""
+
+#: src/main.c:193
+#, c-format
+msgid "Try `%s --help' for more information.\n"
+msgstr ""
+
+#: src/ppastats.c:254
+msgid "Failed to retrieve PPA information"
+msgstr ""
+
+#: src/ppastats.c:269
+#, c-format
+msgid "Failed to retrieve download totals for %s"
+msgstr ""
+
+#: src/ppastats.c:275
+#, c-format
+msgid "Failed to retrieve download count for %s"
+msgstr ""
html.h html.c\
io.h io.c\
list.h list.c\
+ log.h log.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_ppastats_OBJECTS = cache.$(OBJEXT) html.$(OBJEXT) io.$(OBJEXT) \
- list.$(OBJEXT) lp.$(OBJEXT) lp_json.$(OBJEXT) lp_ws.$(OBJEXT) \
- main.$(OBJEXT) ppastats.$(OBJEXT)
+ list.$(OBJEXT) log.$(OBJEXT) lp.$(OBJEXT) lp_json.$(OBJEXT) \
+ lp_ws.$(OBJEXT) main.$(OBJEXT) ppastats.$(OBJEXT)
ppastats_OBJECTS = $(am_ppastats_OBJECTS)
ppastats_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
html.h html.c\
io.h io.c\
list.h list.c\
+ log.h log.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_json.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_ws.Po@am__quote@
02110-1301 USA
*/
+#include <libintl.h>
+#define _(String) gettext(String)
+
#include <string.h>
#include "cache.h"
+#include "log.h"
#include "ppastats.h"
#include <stdlib.h>
for (i = 0; i < cache.size; i++)
if (!strcmp(cache.entries[i].key, key)) {
- if (debug)
- printf("DEBUG: cache hit %s\n", key);
+ log_debug(_("cache hit %s"), key);
return cache.entries[i].value;
}
- if (debug)
- printf("DEBUG: cache miss %s\n", key);
+ log_debug(_("cache miss %s"), key);
return NULL;
}
void (*fct_cleanup)(void *))
{
if (cache.size == CAPACITY) {
- fprintf(stderr, "WARNING: exceed cache capacity\n");
+ log_warn(_("exceed cache capacity"));
return ;
}
02110-1301 USA
*/
+#include <libintl.h>
+#define _(String) gettext(String)
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "html.h"
#include "io.h"
+#include "log.h"
#include "lp.h"
#include "lp_ws.h"
#include "ppastats.h"
f = fopen(path, "w");
if (!f) {
- fprintf(stderr, "ERROR: failed to open: %s\n", path);
+ log_err(_("failed to open: %s"), path);
return ;
}
f = fopen(path, "w");
if (!f) {
- fprintf(stderr, "ERROR: failed to open: %s\n", path);
+ log_err(_("failed to open: %s"), path);
return ;
}
json = ppa_to_json(ppa);
json_path = path_new(dir, "index", ".json");
- if (debug)
- printf("DEBUG: generating %s\n", json_path);
+
+ log_debug(_("generating %s"), json_path);
json_object_to_file(json_path, json);
json_object_put(json);
free(json_path);
json_path = path_new(dir, pkg->name, ".json");
json = pkg_to_json(ppa, pkg);
- if (debug)
- printf("DEBUG: generating %s\n", json_path);
+ log_debug(_("generating %s"), json_path);
+
json_object_to_file(json_path, json);
json_object_put(json);
free(json_path);
1);
sprintf(script, "ppastats_pkg(\"%s%s\");", pkg->name, ".json");
- if (debug)
- printf("DEBUG: generating %s\n", path);
+ log_debug(_("generating %s"), path);
create_html(path, pkg->name, HTML_PKG_TEMPLATE, script);
free(path);
for (i = 0; i < 7; i++) {
f_dst = path_append(output_dir, www_files[2*i+1]);
- if (debug)
- printf("DEBUG: copying %s %s\n",
- www_files[2*i], f_dst);
+ log_debug(_("copying %s %s"), www_files[2*i], f_dst);
fcopy(www_files[2*i], f_dst);
free(f_dst);
--- /dev/null
+/*
+ * Copyright (C) 2010-2012 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include "log.h"
+
+static FILE *file;
+int log_level = LOG_WARN;
+
+void log_open(const char *path)
+{
+ file = fopen(path, "a");
+
+ if (!file)
+ log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
+}
+
+void log_close()
+{
+ if (!file)
+ return ;
+
+ fclose(file);
+
+ file = NULL;
+}
+
+
+#define LOG_BUFFER 4096
+static void vlogf(int lvl, const char *fmt, va_list ap)
+{
+ struct timeval tv;
+ char buffer[1 + LOG_BUFFER];
+ char *lvl_str;
+ FILE *stdf;
+
+ if (lvl > log_level)
+ return ;
+
+ vsnprintf(buffer, LOG_BUFFER, fmt, ap);
+ buffer[LOG_BUFFER] = '\0';
+
+ if (gettimeofday(&tv, NULL) != 0)
+ timerclear(&tv);
+
+ switch (lvl) {
+ case LOG_WARN:
+ lvl_str = "[WARN]";
+ break;
+ case LOG_ERR:
+ lvl_str = "[ERR]";
+ break;
+ case LOG_DEBUG:
+ lvl_str = "[DEBUG]";
+ break;
+ case LOG_INFO:
+ lvl_str = "[INFO]";
+ break;
+ default:
+ lvl_str = "[??]";
+ }
+
+ if (file) {
+ fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+ fflush(file);
+ }
+
+ if (lvl == LOG_WARN || lvl == LOG_ERR)
+ stdf = stderr;
+ else
+ stdf = stdout;
+
+ fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+}
+
+void log_printf(int lvl, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(lvl, fmt, ap);
+ va_end(ap);
+}
+
+void log_debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (log_level < LOG_DEBUG)
+ return ;
+
+ va_start(ap, fmt);
+ vlogf(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+}
+
+void log_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_ERR, fmt, ap);
+ va_end(ap);
+}
+
+void log_warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_WARN, fmt, ap);
+ va_end(ap);
+}
--- /dev/null
+/*
+ * Copyright (C) 2010-2012 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef _PPASTATS_LOG_H_
+#define _PPASTATS_LOG_H_
+
+enum log_level {
+ LOG_ERR ,
+ LOG_WARN,
+ LOG_INFO,
+ LOG_DEBUG
+};
+
+void log_open(const char *path);
+
+void log_printf(int lvl, const char *fmt, ...);
+void log_debug(const char *fmt, ...);
+void log_err(const char *fmt, ...);
+void log_warn(const char *fmt, ...);
+
+void log_close();
+
+/* level of the log file. */
+extern int log_level;
+
+#endif
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
+#include <libintl.h>
+#define _(String) gettext(String)
#include <stdlib.h>
#include <string.h>
#include "cache.h"
#include "list.h"
+#include "log.h"
#include "lp_ws.h"
#include "lp_json.h"
#include "ppastats.h"
long code;
int retries;
- if (debug)
- printf("DEBUG: fetch_url %s\n", url);
+ log_debug(_("fetch_url(): %s"), url);
if (!curl) {
- if (debug)
- printf("DEBUG: initializing CURL\n");
+ log_debug(_("initializing CURL"));
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
}
case 503:
case 504:
if (retries) {
- fprintf(stderr,
- "Fetch failed: with code %ld "
- "for URL= %s\n",
+ log_err(_("Fetch failed with code %ld "
+ "for URL %s"),
code,
url);
- if (debug)
- printf("Wait 5s before retry.\n");
+ log_debug(_("Wait 5s before retry"));
sleep(5);
free(content->data);
goto retrieve;
}
default:
- fprintf(stderr, "Fetch failed: %ld\n", code);
+ log_err(_("Fetch failed: %ld"), code);
}
}
void lp_ws_cleanup()
{
- if (debug)
- printf("DEBUG: cleanup CURL\n");
+ log_debug(_("cleanup CURL"));
curl_easy_cleanup(curl);
curl_global_cleanup();
#include "cache.h"
#include "html.h"
+#include "log.h"
#include "lp_ws.h"
#include "config.h"
#include "ppastats.h"
-int debug;
static const char *program_name;
static void display_published_binaries(const char *owner,
output_dir = strdup(optarg);
break;
case 'd':
- debug = 1;
+ log_level = LOG_DEBUG;
break;
case 'h':
print_help();
02110-1301 USA
*/
+#include <libintl.h>
+#define _(String) gettext(String)
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
+#include "log.h"
#include "lp_ws.h"
#include "ppastats.h"
free(ppa_url);
if (!history) {
- fprintf(stderr, "Failed to retrieve PPA information\n");
+ log_err(_("Failed to retrieve PPA information"));
exit(EXIT_FAILURE);
}
h = *h_cur;
totals = get_daily_download_totals(h->self_link);
if (!totals) {
- fprintf(stderr, "Failed to retrieve download totals"
- " for %s\n", h->self_link);
+ log_err(_("Failed to retrieve download totals for %s"),
+ h->self_link);
continue;
}
count = get_download_count(h->self_link);
if (count == -1) {
- fprintf(stderr, "Failed to retrieve download count"
- " for %s\n", h->self_link);
+ log_err(_("Failed to retrieve download count for %s"),
+ h->self_link);
count = 0;
}
pkg_name = h->binary_package_name;
#ifndef _PPASTATS_PPASTATS_H_
#define _PPASTATS_PPASTATS_H_
-extern int debug;
-
#include "lp.h"
struct arch_stats {