public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage-utils:master commit in: tests/qlop/, /, tests/
@ 2015-05-19 17:37 Mike Frysinger
  0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2015-05-19 17:37 UTC (permalink / raw
  To: gentoo-commits

commit:     ce0ebbec90f6a49648784ce106a4fbaf4def4d7e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue May 19 16:50:04 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> 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 <marduk <AT> 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.


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-05-19 17:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-19 17:37 [gentoo-commits] proj/portage-utils:master commit in: tests/qlop/, /, tests/ Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox