def update(self, mess, args): """ update the bot and/or plugins use : !update all to update everything or : !update core to update only the core or : !update repo_name repo_name ... to update selectively some repos """ directories = set() repos = self.internal_shelf.get('repos', {}) core_to_update = 'all' in args or 'core' in args if core_to_update: directories.add(os.path.dirname(__file__)) if 'all' in args: directories.update([PLUGIN_DIR+os.sep+name for name in repos]) else: directories.update([PLUGIN_DIR+os.sep+name for name in set(args).intersection(set(repos))]) for d in directories: self.send(mess.getFrom(), "I am updating %s ..." % d , message_type=mess.getType()) p = subprocess.Popen(['git', 'pull'], cwd=d, stdout=subprocess.PIPE, stderr=subprocess.PIPE) feedback = p.stdout.read() + '\n' + '-'*50 + '\n' err = p.stderr.read().strip() if err: feedback += err + '\n' + '-'*50 + '\n' if p.wait(): self.send(mess.getFrom(), "Update of %s failed...\n\n%s\n\n resuming..." % (d,feedback) , message_type=mess.getType()) else: self.send(mess.getFrom(), "Update of %s succeeded...\n\n%s\n\n" % (d,feedback) , message_type=mess.getType()) if not core_to_update: for plugin in get_all_plugins(): if plugin.path.startswith(d) and hasattr(plugin,'is_activated') and plugin.is_activated: self.send(mess.getFrom(), '/me is reloading plugin %s' % plugin.name) deactivate_plugin(plugin.name) # calm the plugin down module = __import__(plugin.path.split(os.sep)[-1]) # find back the main module of the plugin reload(module) # reload it class_name = type(plugin.plugin_object).__name__ # find the original name of the class newclass = getattr(module, class_name) # retreive the corresponding new class plugin.plugin_object.__class__ = newclass # BAM, declare the instance of the new type activate_plugin(plugin.name) # wake the plugin up if core_to_update: self.restart(mess, '') return "You have updated the core, I need to restart." return "Done."
def reload(self, mess, args): """reload a plugin""" result = deactivate_plugin(args) + " / " + activate_plugin(args) return result
def load(self, mess, args): """load a plugin""" result = activate_plugin(args) return result