From 6ebb4f23d0eb712607c8ab08dbb0e7ed687d7e6e Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Sat, 1 May 2004 04:57:00 +0000 Subject: [PATCH] better handling of dcclass importing --- direct/src/distributed/ClientDistClass.py | 20 +++++++++++--------- direct/src/distributed/ClientDistUpdate.py | 13 +------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/direct/src/distributed/ClientDistClass.py b/direct/src/distributed/ClientDistClass.py index 19b4f15a47..97be27df6b 100644 --- a/direct/src/distributed/ClientDistClass.py +++ b/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): diff --git a/direct/src/distributed/ClientDistUpdate.py b/direct/src/distributed/ClientDistUpdate.py index f2f3fac0d3..3782e4099f 100644 --- a/direct/src/distributed/ClientDistUpdate.py +++ b/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)