Browse Source

better handling of dcclass importing

Joe Shochet 21 years ago
parent
commit
6ebb4f23d0
2 changed files with 12 additions and 21 deletions
  1. 11 9
      direct/src/distributed/ClientDistClass.py
  2. 1 12
      direct/src/distributed/ClientDistUpdate.py

+ 11 - 9
direct/src/distributed/ClientDistClass.py

@@ -18,21 +18,23 @@ class ClientDistClass:
     def __init__(self, dcClass):
         self.number = dcClass.getNumber()
         self.name = dcClass.getName()
-        self.allFields = self.parseFields(dcClass)
-        self.allCDU = self.createAllCDU(self.allFields)
-        self.number2CDU = self.createNumber2CDUDict(self.allCDU)
-        self.name2CDU = self.createName2CDUDict(self.allCDU)
-        self.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU)
-        self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
 
         stuff = ihooks.current_importer.get_loader().find_module(self.name)
         if not stuff:
             self.notify.warning("Unable to import %s.py" % (self.name))
             self.constructor = None
             return
-
         module = __import__(self.name, moduleGlobals, moduleLocals)
+        # The constructor is really the classObj, which is of course callable
         self.constructor = getattr(module, self.name, None)
+
+        self.allFields = self.parseFields(dcClass)
+        self.allCDU = self.createAllCDU(self.allFields, self.constructor)
+        self.number2CDU = self.createNumber2CDUDict(self.allCDU)
+        self.name2CDU = self.createName2CDUDict(self.allCDU)
+        self.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU)
+        self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
+
         # If this assertion fails, you probably had an import error in
         # a file named in your toon.dc file, or in some file included
         # in a file named in your toon.dc file.
@@ -44,10 +46,10 @@ class ClientDistClass:
             fields.append(dcClass.getInheritedField(i))
         return fields
 
-    def createAllCDU(self, allFields):
+    def createAllCDU(self, allFields, classObj):
         allCDU = []
         for i in allFields:
-            allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i))
+            allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i, classObj))
         return allCDU
 
     def createNumber2CDUDict(self, allCDU):

+ 1 - 12
direct/src/distributed/ClientDistUpdate.py

@@ -14,7 +14,7 @@ moduleLocals = locals()
 class ClientDistUpdate:
     notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate")
 
-    def __init__(self, cdc, dcField):
+    def __init__(self, cdc, dcField, classObj):
         self.cdc = cdc
         self.field = dcField
         self.number = dcField.getNumber()
@@ -22,17 +22,6 @@ class ClientDistUpdate:
         self.types = []
         self.divisors = []
         self.deriveTypesFromParticle(dcField)
-
-        stuff = ihooks.current_importer.get_loader().find_module(cdc.name)
-        if not stuff:
-            # This will be printed by ClientDistClass
-            # self.notify.warning("Unable to import %s.py" % (cdc.name))
-            self.func = None
-            return
-            
-        module = __import__(cdc.name, moduleGlobals, moduleLocals)
-        # If there is no class here, that is an error
-        classObj = getattr(module, cdc.name)
         # If there is no func, it will just be None
         self.func = getattr(classObj, self.name, None)