X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Fns3%2Fns3wrapper_debug.py;h=70a84b7abf2f2c7a43b5f72448082d5e7cb84c98;hb=58a2b493f8df1072a1faa653c8abb6a3f9ba21fa;hp=51eae837c88d8d4ddcc39f7aa05c7a7eb72ee85b;hpb=2d175bc378aa7ec034d24b6d3f04714fd9efab41;p=nepi.git diff --git a/src/nepi/resources/ns3/ns3wrapper_debug.py b/src/nepi/resources/ns3/ns3wrapper_debug.py index 51eae837..70a84b7a 100644 --- a/src/nepi/resources/ns3/ns3wrapper_debug.py +++ b/src/nepi/resources/ns3/ns3wrapper_debug.py @@ -3,9 +3,8 @@ # Copyright (C) 2013 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 @@ -20,8 +19,8 @@ ############ METHODS DEBUG NS3WRAPPER EXECUTION ## -## The ns3wrapper works in an interactive mode, receiving instructions in -## a distributed manner. This makes it very hard to debug scripting errors +## The ns3wrapper works in ditributed mode, receiving instructions from +## a remote client. This makes it very hard to debug scripting errors ## in the client side. To simplify error debugging, when set to debug mode, ## the ns3wrapper dumps every executed line to a script that can be then ## executed locally to reproduce and debug the experiment. @@ -49,9 +48,8 @@ class NS3WrapperDebuger(object): return self._script_path def dump_to_script(self, command): - f = open(self.script_path, "a") - f.write("%s" % command) - f.close() + with open(self.script_path, "a") as f: + f.write("%s" % command) def dump_header(self): if not self.enabled: @@ -160,19 +158,6 @@ wrapper = NS3Wrapper() command = "wrapper.shutdown()\n\n" self.dump_to_script(command) - def dump_add_static_route(self, uuid, args): - if not self.enabled: - return - - command = ("args = %(args)s\n" - "wrapper._add_static_route(%(uuid)s, *args)\n\n" - ) % dict({ - "uuid": self.format_value(uuid), - "args": self.format_args(args), - }) - - self.dump_to_script(command) - def format_value(self, value): if isinstance(value, str) and value.startswith("uuid"): return value.replace("-", "") @@ -181,13 +166,10 @@ wrapper = NS3Wrapper() return pprint.pformat(value) def format_args(self, args): - fargs = map(self.format_value, args) - return "[%s]" % ",".join(fargs) + return "[%s]" % ",".join(self.format_value(arg) for arg in args) def format_kwargs(self, kwargs): - fkwargs = map(lambda (k,w): - "%s: %s" % (self.format_value(k), self.format_value(w)), - kwargs.iteritems()) + fkwargs = ["%s: %s" % (self.format_value(k), self.format_value(v)) for (k, v) in kwargs.items()] return "dict({%s})" % ",".join(fkwargs)