better fix for eval-import problems
This commit is contained in:
parent
73d21894bf
commit
3fd2da4124
|
|
@ -3,7 +3,13 @@
|
|||
from PandaModules import *
|
||||
import DirectNotifyGlobal
|
||||
import ClientDistUpdate
|
||||
import PythonUtil
|
||||
import sys
|
||||
|
||||
# These are stored here so that the distributed classes we load on the fly
|
||||
# can be exec'ed in the module namespace as if we imported them normally.
|
||||
# This is important for redefine to work, and is a good idea anyways.
|
||||
moduleGlobals = globals()
|
||||
moduleLocals = locals()
|
||||
|
||||
class ClientDistClass:
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistClass")
|
||||
|
|
@ -19,19 +25,18 @@ class ClientDistClass:
|
|||
self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
|
||||
|
||||
# Import the class, and store the constructor
|
||||
if not PythonUtil.findPythonModule(self.name):
|
||||
self.notify.warning("%s.py does not exist." % (self.name))
|
||||
try:
|
||||
exec("import " + self.name, moduleGlobals, moduleLocals)
|
||||
except ImportError, e:
|
||||
self.notify.warning("Unable to import %s.py: %s" % (self.name, e))
|
||||
self.constructor = None
|
||||
|
||||
else:
|
||||
exec("import " + self.name)
|
||||
return
|
||||
|
||||
try:
|
||||
self.constructor = eval(self.name + "." + self.name)
|
||||
except (NameError, AttributeError), e:
|
||||
self.notify.warning("%s.%s does not exist: %s" % (self.name, self.name, e))
|
||||
self.constructor = None
|
||||
|
||||
try:
|
||||
self.constructor = eval(self.name + "." + self.name)
|
||||
except (NameError, AttributeError), e:
|
||||
self.notify.warning("%s.%s does not exist: %s" % (self.name, self.name, e))
|
||||
self.constructor = None
|
||||
return
|
||||
|
||||
def parseFields(self, dcClass):
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
import DirectNotifyGlobal
|
||||
import Datagram
|
||||
from MsgTypes import *
|
||||
import PythonUtil
|
||||
|
||||
# These are stored here so that the distributed classes we load on the fly
|
||||
# can be exec'ed in the module namespace as if we imported them normally.
|
||||
|
|
@ -23,21 +22,22 @@ class ClientDistUpdate:
|
|||
self.divisors = []
|
||||
self.deriveTypesFromParticle(dcField)
|
||||
# Figure out our function pointer
|
||||
if not PythonUtil.findPythonModule(cdc.name):
|
||||
# The ClientDistClass already reported this warning.
|
||||
#self.notify.warning("%s.py does not exist." % (cdc.name))
|
||||
self.func = None
|
||||
|
||||
else:
|
||||
try:
|
||||
exec("import " + cdc.name, moduleGlobals, moduleLocals)
|
||||
try:
|
||||
self.func = eval(cdc.name + "." + cdc.name + "." + self.name)
|
||||
# Only catch name and attribute errors
|
||||
# as all other errors are legit errors
|
||||
except (NameError, AttributeError), e:
|
||||
#self.notify.warning(cdc.name + "." + self.name + " does not exist")
|
||||
self.func = None
|
||||
except ImportError, e:
|
||||
# Don't bother reporting this error; the ClientDistClass
|
||||
# will catch it.
|
||||
#self.notify.warning("Unable to import %s.py: %s" % (cdc.name, e))
|
||||
self.func = None
|
||||
return
|
||||
|
||||
try:
|
||||
self.func = eval(cdc.name + "." + cdc.name + "." + self.name)
|
||||
except (NameError, AttributeError), e:
|
||||
# Only catch name and attribute errors
|
||||
# as all other errors are legit errors
|
||||
#self.notify.warning(cdc.name + "." + self.name + " does not exist")
|
||||
self.func = None
|
||||
return
|
||||
|
||||
def deriveTypesFromParticle(self, dcField):
|
||||
|
|
|
|||
Loading…
Reference in New Issue