# 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
############ 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.
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:
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("-", "")
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)