Require new PyBindGen; make it work for Python 2.3.
3 #'my_extra_api_definitions',
11 from pybindgen import FileCodeSink, write_preamble
12 from pybindgen.module import MultiSectionFactory
13 import pybindgen.settings
15 from ns3modulegen_generated import module_init, register_types, register_methods, register_functions
16 import ns3modulegen_core_customizations
19 this_script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
21 class ErrorHandler(pybindgen.settings.ErrorHandler):
22 def handle_error(self, wrapper, exception, traceback_):
24 stack = wrapper.stack_where_defined
25 except AttributeError:
26 print >> sys.stderr, "??:??: %s / %r" % (wrapper, exception)
30 for (filename, line_number, function_name, text) in stack:
31 file_dir = os.path.dirname(os.path.abspath(filename))
32 if file_dir == this_script_dir:
33 print >> sys.stderr, "%s:%i: %r" % (os.path.join("..", "bindings", "python", os.path.basename(filename)),
34 line_number, exception)
37 pybindgen.settings.error_handler = ErrorHandler()
40 class MyMultiSectionFactory(MultiSectionFactory):
42 def __init__(self, main_file_name, modules):
43 super(MyMultiSectionFactory, self).__init__()
44 self.main_file_name = main_file_name
45 self.main_sink = FileCodeSink(open(main_file_name, "wt"))
46 self.header_name = "ns3module.h"
47 header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
48 self.header_sink = FileCodeSink(open(header_file_name, "wt"))
49 self.section_sinks = {}
51 for module in modules:
52 section_name = 'ns3_module_%s' % module.replace('-', '_')
53 file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name)
54 sink = FileCodeSink(open(file_name, "wt"))
55 self.section_sinks[section_name] = sink
57 def get_section_code_sink(self, section_name):
58 return self.section_sinks[section_name]
60 def get_main_code_sink(self):
63 def get_common_header_code_sink(self):
64 return self.header_sink
66 def get_common_header_include(self):
67 return '"%s"' % self.header_name
70 self.header_sink.file.close()
71 self.main_sink.file.close()
72 for sink in self.section_sinks.itervalues():
78 out = MyMultiSectionFactory(sys.argv[1], sys.argv[2:])
79 root_module = module_init()
80 root_module.add_include('"everything.h"')
82 register_types(root_module)
84 ns3modulegen_core_customizations.Simulator_customizations(root_module)
85 ns3modulegen_core_customizations.CommandLine_customizations(root_module)
88 for local_module in LOCAL_MODULES:
89 mod = __import__(local_module)
90 mod.register_types(root_module)
92 ns3modulegen_core_customizations.generate_callback_classes(root_module.after_forward_declarations,
93 callbacks_list.callback_classes)
96 register_methods(root_module)
98 for local_module in LOCAL_MODULES:
99 mod = __import__(local_module)
100 mod.register_methods(root_module)
102 ns3modulegen_core_customizations.Object_customizations(root_module)
103 ns3modulegen_core_customizations.Attribute_customizations(root_module)
105 register_functions(root_module)
107 for local_module in LOCAL_MODULES:
108 mod = __import__(local_module)
109 mod.register_functions(root_module)
112 # if GtkConfigStore support is disabled, disable the class wrapper
113 if 'DISABLE_GTK_CONFIG_STORE' in os.environ:
114 root_module.classes.remove(root_module['ns3::GtkConfigStore'])
116 root_module.generate(out, '_ns3')
120 if __name__ == '__main__':