當前位置: 首頁>>代碼示例>>Python>>正文


Python ModuleFinder.import_hook方法代碼示例

本文整理匯總了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()
開發者ID:BGCX261,項目名稱:zootoolbox-svn-to-git,代碼行數:12,代碼來源:dependencies.py

示例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():
#.........這裏部分代碼省略.........
開發者ID:AdrianF98,項目名稱:Toontown-Rewritten,代碼行數:103,代碼來源:build_client.py


注:本文中的modulefinder.ModuleFinder.import_hook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。