• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python plugin.loadPluginClass函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中supybot.plugin.loadPluginClass函数的典型用法代码示例。如果您正苦于以下问题:Python loadPluginClass函数的具体用法?Python loadPluginClass怎么用?Python loadPluginClass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了loadPluginClass函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _loadPlugins

 def _loadPlugins(self, irc):
     self.log.info('Loading plugins (connecting to %s).', irc.network)
     alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
     important = conf.supybot.commands.defaultPlugins.importantPlugins()
     for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
         if irc.getCallback(name) is None:
             load = value()
             if not load and name in important:
                 if alwaysLoadImportant:
                     s = '%s is configured not to be loaded, but is being '\
                         'loaded anyway because ' \
                         'supybot.plugins.alwaysLoadImportant is True.'
                     self.log.warning(s, name)
                     load = True
             if load:
                 # We don't load plugins that don't start with a capital
                 # letter.
                 if name[0].isupper() and not irc.getCallback(name):
                     # This is debug because each log logs its beginning.
                     self.log.debug('Loading %s.', name)
                     try:
                         m = plugin.loadPluginModule(name,
                                                     ignoreDeprecation=True)
                         plugin.loadPluginClass(irc, m)
                     except callbacks.Error, e:
                         # This is just an error message.
                         log.warning(str(e))
                     except (plugins.NoSuitableDatabase, ImportError), e:
                         s = 'Failed to load %s: %s' % (name, e)
                         if not s.endswith('.'):
                             s += '.'
                         log.warning(s)
                     except Exception, e:
                         log.exception('Failed to load %s:', name)
开发者ID:boamaod,项目名称:Limnoria,代码行数:34,代码来源:plugin.py


示例2: setUp

 def setUp(self, nick='test', forceSetup=False):
     if not forceSetup and \
             self.__class__ in (PluginTestCase, ChannelPluginTestCase):
         # Necessary because there's a test in here that shouldn\'t run.
         return
     SupyTestCase.setUp(self)
     # Just in case, let's do this.  Too many people forget to call their
     # super methods.
     for irc in world.ircs[:]:
         irc._reallyDie()
     # Set conf variables appropriately.
     conf.supybot.reply.whenAddressedBy.chars.setValue('@')
     conf.supybot.reply.error.detailed.setValue(True)
     conf.supybot.reply.whenNotCommand.setValue(True)
     self.myVerbose = world.myVerbose
     def rmFiles(dir):
         for filename in os.listdir(dir):
             file = os.path.join(dir, filename)
             if os.path.isfile(file):
                 os.remove(file)
             else:
                 shutil.rmtree(file)
     if self.cleanConfDir:
         rmFiles(conf.supybot.directories.conf())
     if self.cleanDataDir:
         rmFiles(conf.supybot.directories.data())
     ircdb.users.reload()
     ircdb.ignores.reload()
     ircdb.channels.reload()
     if self.plugins is None:
         raise ValueError, 'PluginTestCase must have a "plugins" attribute.'
     self.nick = nick
     self.prefix = ircutils.joinHostmask(nick, 'user', 'host.domain.tld')
     self.irc = getTestIrc()
     MiscModule = plugin.loadPluginModule('Misc')
     OwnerModule = plugin.loadPluginModule('Owner')
     ConfigModule = plugin.loadPluginModule('Config')
     _ = plugin.loadPluginClass(self.irc, MiscModule)
     _ = plugin.loadPluginClass(self.irc, OwnerModule)
     _ = plugin.loadPluginClass(self.irc, ConfigModule)
     if isinstance(self.plugins, str):
         self.plugins = [self.plugins]
     else:
         for name in self.plugins:
             if name not in ('Owner', 'Misc', 'Config'):
                 module = plugin.loadPluginModule(name,
                                                  ignoreDeprecation=True)
                 cb = plugin.loadPluginClass(self.irc, module)
     self.irc.addCallback(TestInstance)
     for (name, value) in self.config.iteritems():
         group = conf.supybot
         parts = registry.split(name)
         if parts[0] == 'supybot':
             parts.pop(0)
         for part in parts:
             group = group.get(part)
         self.originals[group] = group()
         group.setValue(value)
开发者ID:resistivecorpse,项目名称:Limnoria,代码行数:58,代码来源:test.py


示例3: _loadPlugins

 def _loadPlugins(self, irc):
     self.log.info('Loading plugins (connecting to %s).', irc.network)
     alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
     important = conf.supybot.commands.defaultPlugins.importantPlugins()
     for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
         if irc.getCallback(name) is None:
             load = value()
             if not load and name in important:
                 if alwaysLoadImportant:
                     s = '%s is configured not to be loaded, but is being '\
                         'loaded anyway because ' \
                         'supybot.plugins.alwaysLoadImportant is True.'
                     self.log.warning(s, name)
                     load = True
             if load:
                 # We don't load plugins that don't start with a capital
                 # letter.
                 if name[0].isupper() and not irc.getCallback(name):
                     # This is debug because each log logs its beginning.
                     self.log.debug('Loading %s.', name)
                     try:
                         m = plugin.loadPluginModule(name,
                                                     ignoreDeprecation=True)
                         plugin.loadPluginClass(irc, m)
                     except callbacks.Error as e:
                         # This is just an error message.
                         log.warning(str(e))
                     except plugins.NoSuitableDatabase as e:
                         s = 'Failed to load %s: no suitable database(%s).' % (
                             name, e)
                         log.warning(s)
                     except ImportError as e:
                         e = str(e)
                         if e.endswith(name):
                             s = 'Failed to load {0}: No plugin named {0} exists.'.format(
                                 utils.str.dqrepr(name))
                         elif "No module named 'config'" in e:
                             s = (
                                 "Failed to load %s: This plugin may be incompatible "
                                 "with your current Python version. If this error is appearing "
                                 "with stock Supybot plugins, remove the stock plugins directory "
                                 "(usually ~/Limnoria/plugins) from 'config directories.plugins'." %
                                 name)
                         else:
                             s = 'Failed to load %s: import error (%s).' % (
                                 name, e)
                         log.warning(s)
                     except Exception as e:
                         log.exception('Failed to load %s:', name)
             else:
                 # Let's import the module so configuration is preserved.
                 try:
                     _ = plugin.loadPluginModule(name)
                 except Exception as e:
                     log.debug('Attempted to load %s to preserve its '
                               'configuration, but load failed: %s',
                               name, e)
     world.starting = False
开发者ID:Brilliant-Minds,项目名称:Limnoria-Plugins,代码行数:58,代码来源:plugin.py


示例4: reload

    def reload(self, irc, msg, args, name):
        """<plugin>

        Unloads and subsequently reloads the plugin by name; use the 'list'
        command to see a list of the currently loaded plugins.
        """
        callbacks = irc.removeCallback(name)
        if callbacks:
            module = sys.modules[callbacks[0].__module__]
            if hasattr(module, 'reload'):
                x = module.reload()
            try:
                module = plugin.loadPluginModule(name)
                if hasattr(module, 'reload'):
                    module.reload(x)
                for callback in callbacks:
                    callback.die()
                    del callback
                gc.collect() # This makes sure the callback is collected.
                callback = plugin.loadPluginClass(irc, module)
                irc.replySuccess()
            except ImportError:
                for callback in callbacks:
                    irc.addCallback(callback)
                irc.error('No plugin %s exists.' % name)
        else:
            irc.error('There was no plugin %s.' % name)
开发者ID:boamaod,项目名称:Limnoria,代码行数:27,代码来源:plugin.py


示例5: load

    def load(self, irc, msg, args, optlist, name):
        """[--deprecated] <plugin>

        Loads the plugin <plugin> from any of the directories in
        conf.supybot.directories.plugins; usually this includes the main
        installed directory and 'plugins' in the current directory.
        --deprecated is necessary if you wish to load deprecated plugins.
        """
        ignoreDeprecation = False
        for (option, argument) in optlist:
            if option == 'deprecated':
                ignoreDeprecation = True
        if name.endswith('.py'):
            name = name[:-3]
        if irc.getCallback(name):
            irc.error('%s is already loaded.' % name.capitalize())
            return
        try:
            module = plugin.loadPluginModule(name, ignoreDeprecation)
        except plugin.Deprecated:
            irc.error('%s is deprecated.  Use --deprecated '
                      'to force it to load.' % name.capitalize())
            return
        except ImportError as e:
            if str(e).endswith(name):
                irc.error('No plugin named %s exists.' % utils.str.dqrepr(name))
            else:
                irc.error(str(e))
            return
        cb = plugin.loadPluginClass(irc, module)
        name = cb.name() # Let's normalize this.
        conf.registerPlugin(name, True)
        irc.replySuccess()
开发者ID:nW44b,项目名称:Limnoria,代码行数:33,代码来源:plugin.py


示例6: reload

    def reload(self, irc, msg, args, name):
        """<plugin>

        Unloads and subsequently reloads the plugin by name; use the 'list'
        command to see a list of the currently loaded plugins.
        """
        if ircutils.strEqual(name, self.name()):
            irc.error('You can\'t reload the %s plugin.' % name)
            return
        callbacks = irc.removeCallback(name)
        if callbacks:
            module = sys.modules[callbacks[0].__module__]
            if hasattr(module, 'reload'):
                x = module.reload()
            try:
                module = plugin.loadPluginModule(name)
                if hasattr(module, 'reload') and 'x' in locals():
                    module.reload(x)
                if hasattr(module, 'config'):
                    from imp import reload
                    reload(module.config)
                for callback in callbacks:
                    callback.die()
                    del callback
                gc.collect() # This makes sure the callback is collected.
                callback = plugin.loadPluginClass(irc, module)
                irc.replySuccess()
            except ImportError:
                for callback in callbacks:
                    irc.addCallback(callback)
                irc.error('No plugin named %s exists.' % name)
        else:
            irc.error('There was no plugin %s.' % name)
开发者ID:Hoaas,项目名称:Limnoria,代码行数:33,代码来源:plugin.py


示例7: str

        if irc.getCallback(name):
            irc.error('%s is already loaded.' % name.capitalize())
            return
        try:
            module = plugin.loadPluginModule(name, ignoreDeprecation)
        except plugin.Deprecated:
            irc.error('%s is deprecated.  Use --deprecated '
                      'to force it to load.' % name.capitalize())
            return
        except ImportError, e:
            if str(e).endswith(' ' + name):
                irc.error('No plugin named %s exists.' % utils.str.dqrepr(name))
            else:
                irc.error(str(e))
            return
        cb = plugin.loadPluginClass(irc, module)
        name = cb.name() # Let's normalize this.
        conf.registerPlugin(name, True)
        irc.replySuccess()
    load = wrap(load, [getopts({'deprecated': ''}), 'something'])

    def reload(self, irc, msg, args, name):
        """<plugin>

        Unloads and subsequently reloads the plugin by name; use the 'list'
        command to see a list of the currently loaded plugins.
        """
        callbacks = irc.removeCallback(name)
        if callbacks:
            module = sys.modules[callbacks[0].__module__]
            if hasattr(module, 'reload'):
开发者ID:boamaod,项目名称:Limnoria,代码行数:31,代码来源:plugin.py



注:本文中的supybot.plugin.loadPluginClass函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python plugin.loadPluginModule函数代码示例发布时间:2022-05-27
下一篇:
Python plugin.isCommand函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap