bindings/python/ns3modulescan-modular.py
changeset 6921 f4aa5d190c7b
parent 6902 3aa6e43dfe41
child 6935 7d5937fd65db
--- a/bindings/python/ns3modulescan-modular.py	Sun Mar 20 14:18:56 2011 +0000
+++ b/bindings/python/ns3modulescan-modular.py	Sun Mar 20 15:08:20 2011 +0000
@@ -35,7 +35,10 @@
     l = []
     head = path
     while head:
-        head, tail = os.path.split(head)
+        new_head, tail = os.path.split(head)
+        if new_head == head:
+            raise ValueError
+        head = new_head
         if tail == 'ns3':
             return os.path.join(*l)
         l.insert(0, tail)
@@ -51,7 +54,11 @@
                  pygccxml_definition,
                  global_annotations,
                  parameter_annotations):
-        ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name)
+        try:
+            ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name)
+        except ValueError: # the header is not from ns3
+            return # ignore the definition, it's not ns-3 def.
+
         definition_module = self.headers_map[ns3_header]
 
         ## Note: we don't include line numbers in the comments because
@@ -99,6 +106,7 @@
 
         ## classes
         if isinstance(pygccxml_definition, class_t):
+            print >> sys.stderr, pygccxml_definition
             # no need for helper classes to allow subclassing in Python, I think...
             #if pygccxml_definition.name.endswith('Helper'):
             #    global_annotations['allow_subclassing'] = 'false'
@@ -114,8 +122,17 @@
                 template_parameters_decls = [find_declaration_from_name(module_parser.global_ns, templ_param)
                                              for templ_param in template_parameters]
                 #print >> sys.stderr, "********************", cls_name, repr(template_parameters_decls)
-                template_parameters_modules = [self.headers_map[get_ns3_relative_path(templ.location.file_name)]
-                                               for templ in template_parameters_decls if hasattr(templ, 'location')]
+                
+                template_parameters_modules = []
+                for templ in template_parameters_decls:
+                    if not hasattr(templ, 'location'):
+                        continue
+                    try:
+                        h = get_ns3_relative_path(templ.location.file_name)
+                    except ValueError:
+                        continue
+                    template_parameters_modules.append(self.headers_map[h])
+
                 for templ_mod in template_parameters_modules:
                     if templ_mod == self.module:
                         definition_module = templ_mod