mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
don't wrap import within a try..except block
This commit is contained in:
parent
67942bfee6
commit
b6ec3f4063
@ -3,6 +3,7 @@
|
|||||||
from PandaModules import *
|
from PandaModules import *
|
||||||
import DirectNotifyGlobal
|
import DirectNotifyGlobal
|
||||||
import ClientDistUpdate
|
import ClientDistUpdate
|
||||||
|
import PythonUtil
|
||||||
|
|
||||||
class ClientDistClass:
|
class ClientDistClass:
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistClass")
|
notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistClass")
|
||||||
@ -16,17 +17,22 @@ class ClientDistClass:
|
|||||||
self.name2CDU = self.createName2CDUDict(self.allCDU)
|
self.name2CDU = self.createName2CDUDict(self.allCDU)
|
||||||
self.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU)
|
self.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU)
|
||||||
self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
|
self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
|
||||||
|
|
||||||
# Import the class, and store the constructor
|
# Import the class, and store the constructor
|
||||||
try:
|
if not PythonUtil.findPythonModule(self.name):
|
||||||
exec("import " + self.name)
|
self.notify.warning("%s.py does not exist." % (self.name))
|
||||||
self.constructor = eval(self.name + "." + self.name)
|
|
||||||
except ImportError, e:
|
|
||||||
self.notify.warning("Unable to import %s.py: %s" % (self.name, e))
|
|
||||||
self.constructor = None
|
self.constructor = None
|
||||||
|
|
||||||
|
else:
|
||||||
|
exec("import " + self.name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.constructor = eval(self.name + "." + self.name)
|
||||||
except (NameError, AttributeError), e:
|
except (NameError, AttributeError), e:
|
||||||
self.notify.warning("%s.%s does not exist: %s" % (self.name, self.name, e))
|
self.notify.warning("%s.%s does not exist: %s" % (self.name, self.name, e))
|
||||||
self.constructor = None
|
self.constructor = None
|
||||||
return None
|
|
||||||
|
return
|
||||||
|
|
||||||
def parseFields(self, dcClass):
|
def parseFields(self, dcClass):
|
||||||
fields=[]
|
fields=[]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import DirectNotifyGlobal
|
import DirectNotifyGlobal
|
||||||
import Datagram
|
import Datagram
|
||||||
from MsgTypes import *
|
from MsgTypes import *
|
||||||
|
import PythonUtil
|
||||||
|
|
||||||
# These are stored here so that the distributed classes we load on the fly
|
# 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.
|
# can be exec'ed in the module namespace as if we imported them normally.
|
||||||
@ -22,19 +23,22 @@ class ClientDistUpdate:
|
|||||||
self.divisors = []
|
self.divisors = []
|
||||||
self.deriveTypesFromParticle(dcField)
|
self.deriveTypesFromParticle(dcField)
|
||||||
# Figure out our function pointer
|
# Figure out our function pointer
|
||||||
try:
|
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:
|
||||||
exec("import " + cdc.name, moduleGlobals, moduleLocals)
|
exec("import " + cdc.name, moduleGlobals, moduleLocals)
|
||||||
|
try:
|
||||||
self.func = eval(cdc.name + "." + cdc.name + "." + self.name)
|
self.func = eval(cdc.name + "." + cdc.name + "." + self.name)
|
||||||
# Only catch name and attribute errors
|
# Only catch name and attribute errors
|
||||||
# as all other errors are legit errors
|
# as all other errors are legit errors
|
||||||
except ImportError, e:
|
|
||||||
self.notify.warning("Unable to import %s.py: %s" % (cdc.name, e))
|
|
||||||
self.func = None
|
|
||||||
except (NameError, AttributeError), e:
|
except (NameError, AttributeError), e:
|
||||||
#self.notify.warning(cdc.name + "." + self.name +
|
#self.notify.warning(cdc.name + "." + self.name + " does not exist")
|
||||||
# " does not exist")
|
|
||||||
self.func = None
|
self.func = None
|
||||||
return None
|
|
||||||
|
return
|
||||||
|
|
||||||
def deriveTypesFromParticle(self, dcField):
|
def deriveTypesFromParticle(self, dcField):
|
||||||
dcFieldAtomic = dcField.asAtomicField()
|
dcFieldAtomic = dcField.asAtomicField()
|
||||||
|
@ -5,6 +5,7 @@ import math
|
|||||||
import operator
|
import operator
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# NOTE: ifAbsentPut has been replaced with Python's dictionary's builtin setdefault
|
# NOTE: ifAbsentPut has been replaced with Python's dictionary's builtin setdefault
|
||||||
@ -674,6 +675,18 @@ def lineTag(baseFileName=1, verbose=0, separator=':'):
|
|||||||
return '%s%s%s%s%s' % (fileName, separator, lineNum, separator,
|
return '%s%s%s%s%s' % (fileName, separator, lineNum, separator,
|
||||||
funcName)
|
funcName)
|
||||||
|
|
||||||
|
def findPythonModule(module):
|
||||||
|
# Look along the python load path for the indicated filename.
|
||||||
|
# Returns the located pathname, or None if the filename is not
|
||||||
|
# found.
|
||||||
|
filename = module + '.py'
|
||||||
|
for dir in sys.path:
|
||||||
|
pathname = os.path.join(dir, filename)
|
||||||
|
if os.path.exists(pathname):
|
||||||
|
return pathname
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
class PureVirtual:
|
class PureVirtual:
|
||||||
""" Python classes that want to have C++-style pure-virtual functions
|
""" Python classes that want to have C++-style pure-virtual functions
|
||||||
can derive from this class and call 'derivedMustOverride' from their
|
can derive from this class and call 'derivedMustOverride' from their
|
||||||
|
Loading…
x
Reference in New Issue
Block a user