本文整理汇总了Python中modulefinder.ModuleFinder.import_hook方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleFinder.import_hook方法的具体用法?Python ModuleFinder.import_hook怎么用?Python ModuleFinder.import_hook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modulefinder.ModuleFinder
的用法示例。
在下文中一共展示了ModuleFinder.import_hook方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_hook
# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import import_hook [as 别名]
def import_hook( self, name, caller=None, fromlist=None, level=None ):
if caller is None:
return None
try:
self._callerStack.append( caller.__file__ )
return ModuleFinder.import_hook( self, name, caller, fromlist )
finally:
self._callerStack.pop()
示例2: ClientBuilder
# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import import_hook [as 别名]
class ClientBuilder(object):
MAINMODULE = 'toontown.toonbase.MiraiStart'
def __init__(self, directory, version=None, language='english'):
self.directory = directory
self.version = version or determineVersion(self.directory)
self.language = language.lower()
self.dcfiles = [os.path.join(directory, 'config/otp.dc'),
os.path.join(directory, 'config/toon.dc')]
self.modules = {}
self.path_overrides = {}
self.config_file = os.path.join(self.directory, 'config/public_client.prc')
self.mf = ModuleFinder(sys.path+[self.directory])
from panda3d.direct import DCFile
self.dcf = DCFile()
def should_exclude(self, modname):
# The NonRepeatableRandomSource modules are imported by the dc file explicitly,
# so we have to allow them.
if 'NonRepeatableRandomSource' in modname:
return False
if modname.endswith('AI'):
return True
if modname.endswith('UD'):
return True
if modname.endswith('.ServiceStart'):
return True
def find_excludes(self):
for path, dirs, files in os.walk(self.directory):
for filename in files:
filepath = os.path.join(path, filename)
filepath = os.path.relpath(filepath, self.directory)
if not filepath.endswith('.py'): continue
filepath = filepath[:-3]
modname = filepath.replace(os.path.sep, '.')
if modname.endswith('.__init__'): modname = modname[:-9]
if self.should_exclude(modname):
self.mf.excludes.append(modname)
def find_dcfiles(self):
for path, dirs, files in os.walk(self.directory):
for filename in files:
filepath = os.path.join(path, filename)
if filename.endswith('.dc'):
self.dcfiles.append(filepath)
def create_miraidata(self):
# Create a temporary _miraidata.py and throw it on the path somewhere...
# First, we need the minified DC file contents:
from panda3d.core import StringStream
dcStream = StringStream()
self.dcf.write(dcStream, True)
dcData = dcStream.getData()
# Next we need config files...
configData = []
with open(self.config_file) as f:
fd = f.read()
fd = fd.replace('SERVER_VERSION_HERE', self.version)
fd = fd.replace('LANGUAGE_HERE', self.language)
configData.append(fd)
md = 'CONFIG = %r\nDC = %r\n' % (configData, dcData)
# Now we use tempfile to dump md:
td = tempfile.mkdtemp()
with open(os.path.join(td, '_miraidata.py'), 'w') as f:
f.write(md)
self.mf.path.append(td)
atexit.register(shutil.rmtree, td)
def include_dcimports(self):
for m in xrange(self.dcf.getNumImportModules()):
modparts = self.dcf.getImportModule(m).split('/')
mods = [modparts[0]]
if 'OV' in modparts[1:]:
mods.append(modparts[0]+'OV')
for mod in mods:
self.mf.import_hook(mod)
for s in xrange(self.dcf.getNumImportSymbols(m)):
symparts = self.dcf.getImportSymbol(m,s).split('/')
syms = [symparts[0]]
if 'OV' in symparts[1:]:
syms.append(symparts[0]+'OV')
for sym in syms:
try:
self.mf.import_hook('%s.%s' % (mod,sym))
except ImportError:
pass
def build_modules(self):
for modname, mod in self.mf.modules.items():
#.........这里部分代码省略.........