# PYTHONPATH=$PYTHONPATH:~/repos/nepi/src python src/nepi/resources/ns3/resource_manager_generator.py
#
+from __future__ import print_function
+
# Force the load of ns3 libraries
from nepi.resources.ns3.ns3wrapper import load_ns3_module
base = type_id.LookupByName("ns3::Object")
# Create a .py file using the ns-3 RM template for each ns-3 TypeId
- for i in xrange(tid_count):
+ for i in range(tid_count):
tid = type_id.GetRegistered(i)
(base_class_import, base_class) = select_base_class(ns3, tid)
short_rtype = uncamm_rtype.replace("::","-")
d = os.path.dirname(os.path.realpath(__file__))
- ftemp = open(os.path.join(d, "templates", "resource_manager_template.txt"), "r")
- template = ftemp.read()
- ftemp.close()
+ with open(os.path.join(d, "templates", "resource_manager_template.txt"), "r") as ftemp:
+ template = ftemp.read()
template = template. \
replace("<CLASS_NAME>", classname). \
replace('::', ''). \
replace("-","_").lower() + ".py"
- f = open(os.path.join(d, "classes", fname), "w")
- print os.path.join(d, fname)
- print template
- f.write(template)
- f.close()
+ with open(os.path.join(d, "classes", fname), "w") as f:
+ print(os.path.join(d, fname))
+ print(template)
+ f.write(template)
def template_attributes(ns3, tid):
d = os.path.dirname(os.path.realpath(__file__))
- ftemp = open(os.path.join(d, "templates", "attribute_template.txt"), "r")
- template = ftemp.read()
- ftemp.close()
+ with open(os.path.join(d, "templates", "attribute_template.txt"), "r") as ftemp:
+ template = ftemp.read()
attributes = ""
attr_count = tid.GetAttributeN()
- for i in xrange(attr_count):
+ for i in range(attr_count):
attr_info = tid.GetAttribute(i)
if not attr_info.accessor.HasGetter():
continue
elif isinstance(value, ns3.EnumValue):
attr_type = "Types.Enumerate"
allowed = checker.GetUnderlyingTypeInformation().split("|")
- attr_allowed = "[%s]" % ",".join(map(lambda x: "\"%s\"" % x, allowed))
+ attr_allowed = "[%s]" % ",".join(["\"%s\"" % x for x in allowed])
elif isinstance(value, ns3.DoubleValue):
attr_type = "Types.Double"
# TODO: range
def template_traces(ns3, tid):
d = os.path.dirname(os.path.realpath(__file__))
- ftemp = open(os.path.join(d, "templates", "trace_template.txt"), "r")
- template = ftemp.read()
- ftemp.close()
+ with open(os.path.join(d, "templates", "trace_template.txt"), "r") as ftemp:
+ template = ftemp.read()
traces = ""
trace_count = tid.GetTraceSourceN()
- for i in xrange(trace_count):
+ for i in range(trace_count):
trace_info = tid.GetTraceSource(i)
trace_name = trace_info.name
trace_help = trace_info.help.replace('"', '\\"').replace("'", "\\'")