From eb26e5d2404df23c3151a55a6d887abb421ef601 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Fri, 28 Feb 2014 18:28:31 +0000 Subject: [PATCH] merged plib display date created in the generated html --- NEWS | 6 +++++ po/fr.po | 16 ++++++------ po/ppastats.pot | 16 ++++++------ src/html.c | 3 +++ src/lp_json.c | 2 +- src/lp_json.h | 1 + src/pio.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/pio.h | 4 ++- src/plog.c | 34 ++++++++++++++++++------- src/plog.h | 9 +++++-- src/ppastats.c | 22 ++++++++++++---- src/ppastats.h | 1 + www/js/ppastats.js | 2 ++ www/pkg_version.tpl | 1 + 14 files changed, 152 insertions(+), 38 deletions(-) diff --git a/NEWS b/NEWS index 932ce6d..12d8598 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +v1.2.0 +------ + +* added date created information in the generated HTML for a package + version. + v1.1.0 ------ diff --git a/po/fr.po b/po/fr.po index 627780c..299f6e3 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ppastats 0.0.x\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2014-02-25 13:33+0100\n" +"POT-Creation-Date: 2014-02-27 17:20+0100\n" "PO-Revision-Date: 2012-05-05 23:45+0200\n" "Last-Translator: \n" "Language-Team: French\n" @@ -31,26 +31,26 @@ msgstr "" msgid "exceed cache capacity" msgstr "" -#: src/html.c:351 +#: src/html.c:354 msgid "Failed to get the header template" msgstr "" -#: src/html.c:358 +#: src/html.c:361 #, c-format msgid "Failed to open: %s" msgstr "" -#: src/html.c:404 +#: src/html.c:407 #, c-format msgid "generating %s" msgstr "" -#: src/html.c:471 src/html.c:484 +#: src/html.c:474 src/html.c:487 #, c-format msgid "Generating %s" msgstr "" -#: src/html.c:549 +#: src/html.c:552 #, c-format msgid "Copying %s %s" msgstr "" @@ -145,11 +145,11 @@ msgstr "" msgid "Try `%s --help' for more information.\n" msgstr "" -#: src/ppastats.c:353 +#: src/ppastats.c:363 msgid "Failed to retrieve PPA information" msgstr "" -#: src/ppastats.c:363 +#: src/ppastats.c:373 #, c-format msgid "Failed to retrieve download totals for %s" msgstr "" diff --git a/po/ppastats.pot b/po/ppastats.pot index 2210450..7469094 100644 --- a/po/ppastats.pot +++ b/po/ppastats.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ppastats 1.0.x\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2014-02-25 13:33+0100\n" +"POT-Creation-Date: 2014-02-27 17:20+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -31,26 +31,26 @@ msgstr "" msgid "exceed cache capacity" msgstr "" -#: src/html.c:351 +#: src/html.c:354 msgid "Failed to get the header template" msgstr "" -#: src/html.c:358 +#: src/html.c:361 #, c-format msgid "Failed to open: %s" msgstr "" -#: src/html.c:404 +#: src/html.c:407 #, c-format msgid "generating %s" msgstr "" -#: src/html.c:471 src/html.c:484 +#: src/html.c:474 src/html.c:487 #, c-format msgid "Generating %s" msgstr "" -#: src/html.c:549 +#: src/html.c:552 #, c-format msgid "Copying %s %s" msgstr "" @@ -135,11 +135,11 @@ msgstr "" msgid "Try `%s --help' for more information.\n" msgstr "" -#: src/ppastats.c:353 +#: src/ppastats.c:363 msgid "Failed to retrieve PPA information" msgstr "" -#: src/ppastats.c:363 +#: src/ppastats.c:373 #, c-format msgid "Failed to retrieve download totals for %s" msgstr "" diff --git a/src/html.c b/src/html.c index ea013b6..f24d93e 100644 --- a/src/html.c +++ b/src/html.c @@ -254,6 +254,9 @@ static char *version_to_json(struct ppa_stats *ppa, json_object_object_add(json, "name", json_object_new_string(ver->version)); + json_object_object_add(json, + "date_created", time_to_json(ver->date_created)); + json_add_ddts(json, ver->daily_download_totals); distros = ver->distros; diff --git a/src/lp_json.c b/src/lp_json.c index 8b025f7..5d2d4cd 100644 --- a/src/lp_json.c +++ b/src/lp_json.c @@ -48,7 +48,7 @@ static time_t json_to_time(json_object *json) return -1; } -static json_object *time_to_json(time_t t) +json_object *time_to_json(time_t t) { char *str; json_object *j; diff --git a/src/lp_json.h b/src/lp_json.h index ca082dd..8ffcbaf 100644 --- a/src/lp_json.h +++ b/src/lp_json.h @@ -45,4 +45,5 @@ json_object *ddts_to_json(struct daily_download_total **); struct json_object *date_to_json(struct tm *tm); +json_object *time_to_json(time_t t); #endif diff --git a/src/pio.c b/src/pio.c index 35202a5..701823d 100644 --- a/src/pio.c +++ b/src/pio.c @@ -18,15 +18,16 @@ */ #include +#include #include #include #include #include #include +#include #include - /* Directory separator is \ when cross-compiling for MS Windows systems */ #if defined(__MINGW32__) @@ -234,6 +235,8 @@ file_copy(const char *src, const char *dst) FILE *fsrc, *fdst; int ret = 0; + log_fct("copy %s to %s", src, dst); + fsrc = fopen(src, "r"); if (fsrc) { @@ -283,10 +286,15 @@ char *path_append(const char *dir, const char *path) void mkdirs(const char *dirs, mode_t mode) { - char *c = (char *)dirs; - char *dir = malloc(strlen(dirs) + 1); + char *c, *dir; + int i; + + log_fct("mkdirs %s", dirs); - int i = 0; + c = (char *)dirs; + dir = malloc(strlen(dirs) + 1); + + i = 0; while (*c) { if ((*c == DIRSEP || *c == '\0') && c != dirs) { strncpy(dir, dirs, i); @@ -328,3 +336,60 @@ file_copy_print_error(int code, const char *src, const char *dst) printf("File copy error: unknown error %d.\n", code); } } + +int dir_rcopy(const char *src, const char *dst) +{ + int ret; + char **paths; + FTS *ftsp; + FTSENT *p, *chp; + int fts_options = FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR; + char *p_dst, *n_dst; + + log_fct_enter(); + + log_fct("copy dir %s to %s", src, dst); + + paths = malloc(2 * sizeof(char *)); + paths[0] = strdup(src); + paths[1] = NULL; + + ftsp = fts_open(paths, fts_options, NULL); + if (!ftsp) + return 1; + + chp = fts_children(ftsp, 0); + if (!chp) + return 0; + + n_dst = dir_normalize(dst); + + while ((p = fts_read(ftsp)) != NULL) { + switch (p->fts_info) { + case FTS_D: + p_dst = path_append(n_dst, + p->fts_path + strlen(src) + 1); + mkdirs(p_dst, 0777); + free(p_dst); + break; + case FTS_F: + p_dst = path_append(n_dst, + p->fts_path + strlen(src) + 1); + file_copy(p->fts_path, p_dst); + free(p_dst); + break; + default: + break; + } + } + fts_close(ftsp); + + free(n_dst); + free(paths); + + ret = 0; + + log_fct_exit(); + + return ret; +} diff --git a/src/pio.h b/src/pio.h index a06a690..7b38a41 100644 --- a/src/pio.h +++ b/src/pio.h @@ -20,7 +20,7 @@ #ifndef _P_IO_H #define _P_IO_H -#define P_IO_VER 1 +#define P_IO_VER 2 /* Returns '1' if a given 'path' denotates a directory else returns 0 */ @@ -70,6 +70,8 @@ void file_copy_print_error(int code, const char *src, const char *dst); */ int file_copy(const char *src, const char *dst); +int dir_rcopy(const char *, const char *); + void mkdirs(const char *dirs, mode_t mode); #endif diff --git a/src/plog.c b/src/plog.c index 4cc64a5..21427a9 100644 --- a/src/plog.c +++ b/src/plog.c @@ -55,7 +55,7 @@ void log_close() #define LOG_BUFFER 4096 -static void vlogf(int lvl, const char *fmt, va_list ap) +static void vlogf(int lvl, const char *fct, const char *fmt, va_list ap) { char buffer[1 + LOG_BUFFER]; char *lvl_str, *t; @@ -89,7 +89,11 @@ static void vlogf(int lvl, const char *fmt, va_list ap) return ; if (file && lvl <= log_level) { - fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer); + if (fct) + fprintf(file, + "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer); + else + fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer); fflush(file); } else { t = NULL; @@ -101,8 +105,11 @@ static void vlogf(int lvl, const char *fmt, va_list ap) else stdf = stdout; - - fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer); + if (fct) + fprintf(file, + "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer); + else + fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer); } free(t); @@ -113,7 +120,7 @@ void log_printf(int lvl, const char *fmt, ...) va_list ap; va_start(ap, fmt); - vlogf(lvl, fmt, ap); + vlogf(lvl, NULL, fmt, ap); va_end(ap); } @@ -125,7 +132,7 @@ void log_debug(const char *fmt, ...) return ; va_start(ap, fmt); - vlogf(LOG_DEBUG, fmt, ap); + vlogf(LOG_DEBUG, NULL, fmt, ap); va_end(ap); } @@ -134,7 +141,7 @@ void log_err(const char *fmt, ...) va_list ap; va_start(ap, fmt); - vlogf(LOG_ERR, fmt, ap); + vlogf(LOG_ERR, NULL, fmt, ap); va_end(ap); } @@ -143,7 +150,7 @@ void log_warn(const char *fmt, ...) va_list ap; va_start(ap, fmt); - vlogf(LOG_WARN, fmt, ap); + vlogf(LOG_WARN, NULL, fmt, ap); va_end(ap); } @@ -152,6 +159,15 @@ void log_info(const char *fmt, ...) va_list ap; va_start(ap, fmt); - vlogf(LOG_INFO, fmt, ap); + vlogf(LOG_INFO, NULL, fmt, ap); + va_end(ap); +} + +void _log(const char *fct, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vlogf(LOG_DEBUG, fct, fmt, ap); va_end(ap); } diff --git a/src/plog.h b/src/plog.h index 185af1a..29880e9 100644 --- a/src/plog.h +++ b/src/plog.h @@ -19,7 +19,7 @@ #ifndef _P_LOG_H_ #define _P_LOG_H_ -#define P_LOG_VER 1 +#define P_LOG_VER 2 enum log_level { LOG_ERR , @@ -29,6 +29,7 @@ enum log_level { }; void log_open(const char *path); +void log_close(); void log_printf(int lvl, const char *fmt, ...); void log_debug(const char *fmt, ...); @@ -36,7 +37,11 @@ void log_err(const char *fmt, ...); void log_info(const char *fmt, ...); void log_warn(const char *fmt, ...); -void log_close(); +void _log(const char *fct, const char *fmt, ...); + +#define log_fct(...) _log(__func__, __VA_ARGS__) +#define log_fct_enter() log_fct("ENTER") +#define log_fct_exit() log_fct("EXIT") /* level of the log file. */ extern int log_level; diff --git a/src/ppastats.c b/src/ppastats.c index c1c18d8..a03ecf0 100644 --- a/src/ppastats.c +++ b/src/ppastats.c @@ -147,6 +147,20 @@ static struct package_stats *get_package_stats(struct ppa_stats *stats, return p; } +static struct version_stats *version_stats_new(const char *version) +{ + struct version_stats *v; + + v = malloc(sizeof(struct version_stats)); + v->version = strdup(version); + v->distros = NULL; + v->download_count = 0; + v->daily_download_totals = NULL; + v->date_created = 0; + + return v; +} + static struct version_stats *get_version_stats(struct package_stats *package, const char *version) { @@ -162,11 +176,7 @@ static struct version_stats *get_version_stats(struct package_stats *package, cur++; } - v = malloc(sizeof(struct version_stats)); - v->version = strdup(version); - v->distros = NULL; - v->download_count = 0; - v->daily_download_totals = NULL; + v = version_stats_new(version); tmp = (struct version_stats **)list_add((void **)package->versions, v); @@ -386,6 +396,8 @@ create_ppa_stats(const char *owner, pkg->daily_download_totals = tmp; version = get_version_stats(pkg, pkg_version); + version->date_created = h->date_created; + version->download_count += count; tmp = add_totals(version->daily_download_totals, totals); if (version->daily_download_totals != tmp) diff --git a/src/ppastats.h b/src/ppastats.h index 9127731..8a13348 100644 --- a/src/ppastats.h +++ b/src/ppastats.h @@ -38,6 +38,7 @@ struct distro_stats { struct version_stats { char *version; + time_t date_created; struct distro_stats **distros; int download_count; diff --git a/www/js/ppastats.js b/www/js/ppastats.js index 1824508..8217d55 100644 --- a/www/js/ppastats.js +++ b/www/js/ppastats.js @@ -130,6 +130,8 @@ function ppastats_ver() { }); ppastats_chart(data["ddts"]); + + $("#date_created").append(data["date_created"]); }); } diff --git a/www/pkg_version.tpl b/www/pkg_version.tpl index 0af0899..c541c85 100644 --- a/www/pkg_version.tpl +++ b/www/pkg_version.tpl @@ -9,6 +9,7 @@ Package: N/A
Version:
+
Date created:
Distributions:
-- 2.7.4