From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 65842138CD0 for ; Tue, 19 May 2015 17:37:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 71B6EE0A53; Tue, 19 May 2015 17:37:28 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8A137E0A53 for ; Tue, 19 May 2015 17:37:27 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B17AB340BBE for ; Tue, 19 May 2015 17:37:26 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 106909F8 for ; Tue, 19 May 2015 17:37:24 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1432054204.ce0ebbec90f6a49648784ce106a4fbaf4def4d7e.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: tests/qlop/, /, tests/ X-VCS-Repository: proj/portage-utils X-VCS-Files: qlop.c tests/Makefile tests/qlop/Makefile tests/qlop/dotest tests/qlop/list01.good tests/qlop/sync.log X-VCS-Directories: tests/qlop/ / tests/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: ce0ebbec90f6a49648784ce106a4fbaf4def4d7e X-VCS-Branch: master Date: Tue, 19 May 2015 17:37:24 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 26afb744-0f6c-41f5-80b0-79dd56355761 X-Archives-Hash: 70262848b74ee8a8f94cdc13f4ea138d commit: ce0ebbec90f6a49648784ce106a4fbaf4def4d7e Author: Mike Frysinger gentoo org> AuthorDate: Tue May 19 16:50:04 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Tue May 19 16:50:04 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ce0ebbec qlop: support new sync log format Portage updated the format of sync entries, so update the parser as well. URL: https://bugs.gentoo.org/540400 Reported-by: Albert W. Hopkins python.net> qlop.c | 54 ++++++++++++++++++++++++++++++++++++++------------ tests/Makefile | 2 +- tests/qlop/Makefile | 11 ++++++++++ tests/qlop/dotest | 30 ++++++++++++++++++++++++++++ tests/qlop/list01.good | 2 ++ tests/qlop/sync.log | 13 ++++++++++++ 6 files changed, 98 insertions(+), 14 deletions(-) diff --git a/qlop.c b/qlop.c index a2541e2..93dbcc8 100644 --- a/qlop.c +++ b/qlop.c @@ -304,12 +304,31 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile) fclose(fp); } +/* The format of the sync log has changed over time. + +Old format: +1106804103: Started emerge on: Jan 27, 2005 05:35:03 +1106804103: *** emerge sync +1106804103: === sync +1106804103: >>> starting rsync with rsync://192.168.0.5/gentoo-portage +1106804537: === Sync completed with rsync://192.168.0.5/gentoo-portage +1106804538: *** terminating. + +New format: +1431764402: Started emerge on: May 16, 2015 04:20:01 +1431764402: *** emerge --quiet --keep-going --verbose --nospinner --oneshot --quiet-build=n --sync +1431764402: === sync +1431764402: >>> Syncing repository 'gentoo' into '/usr/portage'... +1431764402: >>> Starting rsync with rsync://[2a01:90:200:10::1a]/gentoo-portage +1431764460: === Sync completed for gentoo +1431764493: *** terminating. +*/ _q_static void show_sync_history(const char *logfile) { FILE *fp; - size_t buflen; - char *buf, *p, *q; + size_t buflen, len; + char *buf, *p; time_t t; if ((fp = fopen(logfile, "r")) == NULL) { @@ -318,26 +337,35 @@ show_sync_history(const char *logfile) } buf = NULL; + /* Just find the finish lines. */ while (getline(&buf, &buflen, fp) != -1) { - if (strlen(buf) < 35) - continue; - if (strncmp(buf+12, "=== Sync completed with", 23) != 0) + len = strlen(buf); + /* This cuts out like ~10% of the log. */ + if (len < 35) continue; - if ((p = strchr(buf, '\n')) != NULL) - *p = 0; + /* Make sure there's a timestamp in here. */ if ((p = strchr(buf, ':')) == NULL) continue; - *p = 0; - q = p+2; + p += 2; + + if (strncmp(p, "=== Sync completed ", 19) != 0) + continue; + p += 19; + + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; t = (time_t)atol(buf); - if ((p = strstr(q, "with")) == NULL) + if (!strncmp(p, "with ", 5)) + p += 5; + else if (!strncmp(p, "for ", 4)) + /* This shows just the repo name not the remote host ... */ + p += 4; + else continue; - q = p + 5; - - printf("%s >>> %s%s%s\n", chop_ctime(t), GREEN, q, NORM); + printf("%s >>> %s%s%s\n", chop_ctime(t), GREEN, p, NORM); } free(buf); diff --git a/tests/Makefile b/tests/Makefile index c0aedb4..b4d6005 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ TESTS = \ reinitialize atom_compare atom_explode mkdir \ - qcheck qdepends qfile qlist qmerge qtbz2 quse qxpak \ + qcheck qdepends qfile qlist qlop qmerge qtbz2 quse qxpak \ install profile source all: check diff --git a/tests/qlop/Makefile b/tests/qlop/Makefile new file mode 100644 index 0000000..11a6921 --- /dev/null +++ b/tests/qlop/Makefile @@ -0,0 +1,11 @@ +thisdir = qlop +include ../subdir.mk + +all: check + +test check: + $(Q)$(s)/dotest + +clean: + +.PHONY: all check clean test diff --git a/tests/qlop/dotest b/tests/qlop/dotest new file mode 100755 index 0000000..8182e67 --- /dev/null +++ b/tests/qlop/dotest @@ -0,0 +1,30 @@ +#!/bin/bash + +. ../init.sh + +set -e + +mktmpdir + +test() { + local num=$1 exp=$2 ret=0 + shift 2 + eval "$@" > list || ret=$? + if ! diff -u list ${as}/list${num}.good ; then + tfail "output does not match" + fi + if [[ ${exp} -ne ${ret} ]] ; then + tfail "exit code (${ret}) does not match expected (${exp})" + fi + tend $? "$*" +} + +# We output dates, so make sure it matches our logs. +export LC_TIME="C" + +# simple install check +test 01 0 "qlop -s -f ${as}/sync.log" + +cleantmpdir + +end diff --git a/tests/qlop/list01.good b/tests/qlop/list01.good new file mode 100644 index 0000000..458c751 --- /dev/null +++ b/tests/qlop/list01.good @@ -0,0 +1,2 @@ +Thu Jan 27 00:42:17 2005 >>> rsync://192.168.0.5/gentoo-portage +Sat May 16 04:21:00 2015 >>> gentoo diff --git a/tests/qlop/sync.log b/tests/qlop/sync.log new file mode 100644 index 0000000..fc31edb --- /dev/null +++ b/tests/qlop/sync.log @@ -0,0 +1,13 @@ +1106804103: Started emerge on: Jan 27, 2005 05:35:03 +1106804103: *** emerge sync +1106804103: === sync +1106804103: >>> starting rsync with rsync://192.168.0.5/gentoo-portage +1106804537: === Sync completed with rsync://192.168.0.5/gentoo-portage +1106804538: *** terminating. +1431764402: Started emerge on: May 16, 2015 04:20:01 +1431764402: *** emerge --quiet --keep-going --verbose --nospinner --oneshot --quiet-build=n --sync +1431764402: === sync +1431764402: >>> Syncing repository 'gentoo' into '/usr/portage'... +1431764402: >>> Starting rsync with rsync://[2a01:90:200:10::1a]/gentoo-portage +1431764460: === Sync completed for gentoo +1431764493: *** terminating.