qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject [qpid-dispatch] branch master updated: DISPATCH-1550: Add custom parser for router link state costs
Date Tue, 21 Jan 2020 20:16:01 GMT
This is an automated email from the ASF dual-hosted git repository.

chug pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new a43b948  DISPATCH-1550: Add custom parser for router link state costs
a43b948 is described below

commit a43b94858043a87397d67d16040d8867c220437c
Author: Chuck Rolke <chug@apache.org>
AuthorDate: Tue Jan 21 14:58:00 2020 -0500

    DISPATCH-1550: Add custom parser for router link state costs
    
    ast.literal_eval stopped evaluating acceptably.
---
 tools/scraper/common.py  | 23 +++++++++++++++++++++++
 tools/scraper/scraper.py | 10 +++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/tools/scraper/common.py b/tools/scraper/common.py
index 3d52b1a..8f2b9c0 100755
--- a/tools/scraper/common.py
+++ b/tools/scraper/common.py
@@ -196,3 +196,26 @@ def strings_of_proton_log(text):
                 skipping = False
                 r += elem
     return r
+
+def ls_eval(text):
+    '''
+    Given a router_ls cost string like '{u'A': 1, u'C': 51L, u'B': 101L}',
+    return a dictionary {A:1, C:51, B:101}
+    This code replaces ast.literal_eval
+    '''
+    result = {}
+    text = text.strip(" {}")
+    if len(text) > 0:
+        items = text.split(', ')
+        for item in items:
+            kv = item.split(": ")
+            key = kv[0].strip()
+            if key.startswith("u'") or key.startswith('u"'):
+                key = key[2:-1]
+            elif key.startswith("'"):
+                key = key[1:-1]
+            val = kv[1].strip()
+            if val.endswith("L"):
+                val = val[:-1]
+            result[key] = int(val)
+    return result
diff --git a/tools/scraper/scraper.py b/tools/scraper/scraper.py
index 3dfde07..5061129 100755
--- a/tools/scraper/scraper.py
+++ b/tools/scraper/scraper.py
@@ -34,7 +34,6 @@ from __future__ import absolute_import
 from __future__ import print_function
 
 import argparse
-import ast
 import os
 import sys
 import traceback
@@ -834,7 +833,12 @@ def main_except(argv):
                 line = plf.line
                 sti = line.find("{")
                 line = line[sti:]
-                l_dict = ast.literal_eval(line)
+                try:
+                    l_dict = common.ls_eval(line)
+                except:
+                    traceback.print_exc()
+                    sys.stderr.write("Failed to parse router %s, line %d : %s. Analysis continuing...\n"
% (plf.router.iname, plf.lineno, plf.line))
+                    l_dict = {}
                 costs_row = new_costs_row(PEER_COST_ABSENT)
                 for i in range(0, comn.n_logs):
                     if len(comn.routers[i]) > 0:
@@ -859,7 +863,7 @@ def main_except(argv):
                 if plf.router.is_interior():
                     cur_costs[plf.router.container_name] = costs_row
             except:
-                pass
+                raise
             print("</tr>")
             # if the costs are stable across all routers then put an indicator in table
             costs_stable = True


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message