Commits

Frederic De Groef committed caeb1f5

updated error listing tool

Comments (0)

Files changed (1)

scripts/csxj_list_errors.py

 from csxj.db import Provider, get_all_provider_names
+from csxj.db import ErrorLogEntry, ErrorLogEntry2
+import itertools as it
+
+def filter_identical_ErrorLogEntries(entries):
+    if entries:
+        def keyfunc(a):
+            return a.__class__
+
+        splitted = dict()
+        for k, g in it.groupby(entries, key=keyfunc):
+            splitted[k] = list(g)
+
+        out = splitted[ErrorLogEntry2]
+        out_urls = [e.url for e in out]
+        if ErrorLogEntry in splitted:
+            non_duplicates = [ErrorLogEntry2(url=e.url, title=e.filename, stacktrace=e.stacktrace) for e in splitted[ErrorLogEntry] if e.url not in out_urls]
+            out.extend(non_duplicates)
+        return out
+    else:
+        return list()
+
+
+def flatten_list(entries):
+    return [e[0] for e in entries if e]
 
 
 def list_errors(db_root):
         for date_string in provider_db.get_all_days():
             errors_by_batch = provider_db.get_errors2_per_batch(date_string)
 
-            for (time, errors) in errors_by_batch:
-                if errors:
-                    error_count += len(errors)
-                    print source_name, date_string, time
-                    for err in errors:
-                        print "\t", err.url
+            for (batch_time, errors) in errors_by_batch:
+                print source_name, date_string, batch_time
+
+                errors = flatten_list(errors)
+                errors = filter_identical_ErrorLogEntries(errors)
+                error_count += len(errors)
+
+                for e in errors:
+                    print e.url
+
         res[source_name] = error_count
 
     print "\n" * 4