X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fdata%2Fprocessing%2Fping%2Fparser.py;h=d531118b4a7cbeb987c960d31f48fd290da35ba7;hb=6285ca51026efb69642eea9dfc7c480e722d84a9;hp=c5745a1f52cf33c1b0bc19f8a971fd8f79c99acc;hpb=d16b306c7ee05bd2f068966bead8906526368162;p=nepi.git diff --git a/src/nepi/data/processing/ping/parser.py b/src/nepi/data/processing/ping/parser.py index c5745a1f..d531118b 100644 --- a/src/nepi/data/processing/ping/parser.py +++ b/src/nepi/data/processing/ping/parser.py @@ -6,9 +6,8 @@ # Copyright (C) 2014 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -40,29 +39,27 @@ def parse_file(filename): """ - f = open(filename, "r") + with open(filename, "r") as f: - # Traceroute info - target_ip = None - target_hostname = None + # Traceroute info + target_ip = None + target_hostname = None - data = [] - - for line in f: - # match traceroute to ... - m = re.match(_rre, line) - if not m: - continue - - target_ip = m.groupdict()["ip"] - # FIX THIS: Make sure the regular expression does not inlcude - # the ')' in the ip group - target_ip = target_ip.replace(")","") - target_hostname = m.groupdict()["hostname"] - time = m.groupdict()["time"] - data.append((target_ip, target_hostname, time)) - - f.close() + data = [] + + for line in f: + # match traceroute to ... + m = re.match(_rre, line) + if not m: + continue + + target_ip = m.groupdict()["ip"] + # FIX THIS: Make sure the regular expression does not inlcude + # the ')' in the ip group + target_ip = target_ip.replace(")","") + target_hostname = m.groupdict()["hostname"] + time = m.groupdict()["time"] + data.append((target_ip, target_hostname, time)) return data @@ -109,7 +106,7 @@ def annotate_cn_graph(logs_dir, graph): if not found_files: msg = "No PING output files were found to parse at %s " % logs_dir - raise RuntimeError, msg + raise RuntimeError(msg) # Take as weight the most frequent value for nid1, nid2 in graph.edges():