better handling of dcclass importing

This commit is contained in:
Joe Shochet 2004-05-01 04:57:00 +00:00
parent 2dc81f276c
commit 6ebb4f23d0
2 changed files with 12 additions and 21 deletions

View File

@ -18,21 +18,23 @@ class ClientDistClass:
def __init__(self, dcClass): def __init__(self, dcClass):
self.number = dcClass.getNumber() self.number = dcClass.getNumber()
self.name = dcClass.getName() 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) stuff = ihooks.current_importer.get_loader().find_module(self.name)
if not stuff: if not stuff:
self.notify.warning("Unable to import %s.py" % (self.name)) self.notify.warning("Unable to import %s.py" % (self.name))
self.constructor = None self.constructor = None
return return
module = __import__(self.name, moduleGlobals, moduleLocals) 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.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 # If this assertion fails, you probably had an import error in
# a file named in your toon.dc file, or in some file included # a file named in your toon.dc file, or in some file included
# in a file named in your toon.dc file. # in a file named in your toon.dc file.
@ -44,10 +46,10 @@ class ClientDistClass:
fields.append(dcClass.getInheritedField(i)) fields.append(dcClass.getInheritedField(i))
return fields return fields
def createAllCDU(self, allFields): def createAllCDU(self, allFields, classObj):
allCDU = [] allCDU = []
for i in allFields: for i in allFields:
allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i)) allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i, classObj))
return allCDU return allCDU
def createNumber2CDUDict(self, allCDU): def createNumber2CDUDict(self, allCDU):

View File

@ -14,7 +14,7 @@ moduleLocals = locals()
class ClientDistUpdate: class ClientDistUpdate:
notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate") notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate")
def __init__(self, cdc, dcField): def __init__(self, cdc, dcField, classObj):
self.cdc = cdc self.cdc = cdc
self.field = dcField self.field = dcField
self.number = dcField.getNumber() self.number = dcField.getNumber()
@ -22,17 +22,6 @@ class ClientDistUpdate:
self.types = [] self.types = []
self.divisors = [] self.divisors = []
self.deriveTypesFromParticle(dcField) 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 # If there is no func, it will just be None
self.func = getattr(classObj, self.name, None) self.func = getattr(classObj, self.name, None)