コード例 #1
0
ファイル: cmds.py プロジェクト: dequis/dekisu
 def cmd_eval(self):
     '''this is a docstring i just added'''
     import code
     codestring = self.params.replace("[NL]", "\n")
     try:
         return str(eval(compile(codestring, '<irc>', 'eval')))
     except Exception:
         self.enable_stdout()
         try:
             eval(code.compile_command(codestring))
         except Exception:
             return util.exc_lines()[-1]
         self.disable_stdout()
コード例 #2
0
ファイル: cmds.py プロジェクト: dequis/dekisu
    def cmd_module(self, action, modules):
        modules = modules and modules.split() or []
    
        for module in modules:
            try:
                if action == 'load' and module not in self.storage['modules']:
                    mod = util.get_module(module)
                    mod.load(self.handler)
                    
                    if getattr(mod, 'PROVIDES_COMMANDS', None):
                        for cmd in mod.PROVIDES_COMMANDS:
                            self.storage['extra_commands'][cmd] = module
                    
                    self.storage['modules'].append(module)
                    self.storage.touch()
                elif action == 'unload' and module in self.storage['modules']:
                    self.storage['modules'].remove(module)
                    self.storage.touch()
                    mod = util.get_module(module)
                    mod.unload(self.handler)
                    
                    if getattr(mod, 'PROVIDES_COMMANDS', None):
                        for cmd in mod.PROVIDES_COMMANDS:
                            if cmd in self.storage['extra_commands']:
                                del self.storage['extra_commands'][cmd]
                        self.storage.touch()
            except:
                yield "%s: %s" % (module, util.exc_lines()[-1])
            else:
                yield '%s: done' % module
 
        if action == 'list':
            modules = self.storage['modules']
            all = [x.replace(".py", "").replace("mods/", "") for x in glob.glob("mods/*.py")]
            all = [x + (x in modules and "*" or "") for x in all if not x.startswith("_")]
            yield ', '.join(sorted(all))