[Piuparts-devel] [PATCH 1/3] piuparts-analyze.py: rewrite extract_errors to behave like 'grep -i error'

debian at mikapflueger.de debian at mikapflueger.de
Fri Jul 29 13:41:11 UTC 2011


From: Mika Pflüger <mika at mikapflueger.de>

This is pretty stupid behaviour, but better than the old one which
matched lines with the verison number of the package and (worse) the
download speed of apt.
Also adds the removal of chroot temp name and package version from error lines.
---
 piuparts-analyze.py |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/piuparts-analyze.py b/piuparts-analyze.py
index 15ad1d5..81907cb 100644
--- a/piuparts-analyze.py
+++ b/piuparts-analyze.py
@@ -34,7 +34,8 @@ import shutil
 import sys
 
 
-error_pattern = re.compile(r"(?<=\n)(\d+m\d+\.\d+s ERROR: .*\n(  .*\n)*\n?)+")
+error_pattern = re.compile(r"(?<=\n).*error.*\n?", flags=re.IGNORECASE)
+chroot_pattern = re.compile(r"tmp/tmp.*?'")
 
 
 def find_logs(dir):
@@ -53,23 +54,25 @@ def find_bugged_logs(failed_log):
 
 
 def extract_errors(log):
-    f = file(log, "r")
+    """This pretty stupid implementation is basically just 'grep -i error', and then
+    removing the timestamps and the name of the chroot and the package version itself."""
+    f = open(log)
     data = f.read()
     f.close()
-    m = error_pattern.search(data)
-    if m:
-        text = m.group()
+    whole = ''
+    pversion = package_version(log)
+    for match in error_pattern.finditer(data):
+        text = match.group()
         # Get rid of timestamps
-        text2 = []
-        for line in text.split("\n"):
-            if line[:1].isdigit():
-                text2.append(line.split(" ", 1)[1])
-            else:
-                text2.append(line)
-        return "\n".join(text2)
-    else:
-        return None
-
+        if text[:1].isdigit():
+            text = text.split(" ", 1)[1]
+        # Get rid of chroot names
+        if 'tmp/tmp' in text:
+            text = re.sub(chroot_pattern, "chroot'", text)
+        # Get rid of the package version
+        text = text.replace(pversion, '')
+        whole += text
+    return whole
 
 def extract_headers(log):
     f = file(log, "r")
-- 
1.7.5.4




More information about the Piuparts-devel mailing list