def repos_update(self, mess, args): """ update the bot and/or plugins use : !repos update all to update everything or : !repos update core to update only the core or : !repos update repo_name repo_name ... to update selectively some repos """ git_path = which('git') if not git_path: return 'git command not found: You need to have git installed on your system to by able to update git based plugins.' directories = set() repos = self.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_path, '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' dep_err = check_dependencies(d) if dep_err: feedback += dep_err + '\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: name = plugin.name self.send(mess.getFrom(), '/me is reloading plugin %s' % name) self.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 self.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 repos_update(self, mess, args): """ update the bot and/or plugins use : !repos update all to update everything or : !repos update core to update only the core or : !repos update repo_name repo_name ... to update selectively some repos """ git_path = which('git') if not git_path: return 'git command not found: You need to have git installed on your system to by able to update git based plugins.' directories = set() repos = self.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([self.plugin_dir + os.sep + name for name in repos]) else: directories.update([self.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_path, 'pull'], cwd=d, stdout=subprocess.PIPE, stderr=subprocess.PIPE) feedback = p.stdout.read().decode('utf-8') + '\n' + '-' * 50 + '\n' err = p.stderr.read().strip().decode('utf-8') if err: feedback += err + '\n' + '-' * 50 + '\n' dep_err = check_dependencies(d) if dep_err: feedback += dep_err + '\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: name = plugin.name self.send(mess.getFrom(), '/me is reloading plugin %s' % name) self.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 self.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 repos_update(self, mess, args): """ update the bot and/or plugins use : !repos update all to update everything or : !repos update core to update only the core or : !repos update repo_name repo_name ... to update selectively some repos """ git_path = which('git') if not git_path: return ('git command not found: You need to have git installed on ' 'your system to be able to install git based plugins.') directories = set() repos = self.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([self.plugin_dir + os.sep + name for name in repos]) else: directories.update([self.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_path, 'pull'], cwd=d, stdout=subprocess.PIPE, stderr=subprocess.PIPE) feedback = p.stdout.read().decode('utf-8') + '\n' + '-' * 50 + '\n' err = p.stderr.read().strip().decode('utf-8') if err: feedback += err + '\n' + '-' * 50 + '\n' dep_err = check_dependencies(d) if dep_err: feedback += dep_err + '\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: name = plugin.name self.send(mess.getFrom(), '/me is reloading plugin %s' % name) reload_plugin_by_name(plugin.name) self.activate_plugin(plugin.name) self.send(mess.getFrom(), '%s reloaded and reactivated' % name) if core_to_update: self.restart(mess, '') return "You have updated the core, I need to restart." return "Done."
def activate_non_started_plugins(self): logging.info('Activating all the plugins...') configs = self['configs'] errors = '' for pluginInfo in get_all_plugins(): try: if self.is_plugin_blacklisted(pluginInfo.name): errors += 'Notice: %s is blacklisted, use ' + BOT_PREFIX + 'load %s to unblacklist it\n' % (pluginInfo.name, pluginInfo.name) continue if hasattr(pluginInfo, 'is_activated') and not pluginInfo.is_activated: logging.info('Activate plugin: %s' % pluginInfo.name) activate_plugin_with_version_check(pluginInfo.name, configs.get(pluginInfo.name, None)) except Exception, e: logging.exception("Error loading %s" % pluginInfo.name) errors += 'Error: %s failed to start : %s\n' % (pluginInfo.name ,e)
def activate_non_started_plugins(self): logging.info('Activating all the plugins...') configs = self[CONFIGS] errors = '' for pluginInfo in get_all_plugins(): try: if self.is_plugin_blacklisted(pluginInfo.name): errors += ('Notice: %s is blacklisted, use ' + self.prefix + 'load %s to unblacklist it\n') % (pluginInfo.name, pluginInfo.name) continue if hasattr(pluginInfo, 'is_activated') and not pluginInfo.is_activated: logging.info('Activate plugin: %s' % pluginInfo.name) activate_plugin_with_version_check(pluginInfo.name, configs.get(pluginInfo.name, None)) except Exception as e: logging.exception("Error loading %s" % pluginInfo.name) errors += 'Error: %s failed to start : %s\n' % (pluginInfo.name, e) if errors: self.warn_admins(errors) return errors
def activate_non_started_plugins(self): logging.info("Activating all the plugins...") configs = self["configs"] errors = "" for pluginInfo in get_all_plugins(): try: if self.is_plugin_blacklisted(pluginInfo.name): errors += ( "Notice: %s is blacklisted, use " + BOT_PREFIX + "load %s to unblacklist it\n" % (pluginInfo.name, pluginInfo.name) ) continue if hasattr(pluginInfo, "is_activated") and not pluginInfo.is_activated: logging.info("Activate plugin: %s" % pluginInfo.name) activate_plugin_with_version_check(pluginInfo.name, configs.get(pluginInfo.name, None)) except Exception, e: logging.exception("Error loading %s" % pluginInfo.name) errors += "Error: %s failed to start : %s\n" % (pluginInfo.name, e)
def repos_uninstall(self, mess, args): """ uninstall a plugin repository by name. """ if not args.strip(): return "You should have a repo name as argument" repos = self.get("repos", {}) if not repos.has_key(args): return "This repo is not installed check with ' + BOT_PREFIX + 'repos the list of installed ones" plugin_path = PLUGIN_DIR + os.sep + args for plugin in get_all_plugins(): if plugin.path.startswith(plugin_path) and hasattr(plugin, "is_activated") and plugin.is_activated: self.send(mess.getFrom(), "/me is unloading plugin %s" % plugin.name) self.deactivate_plugin(plugin.name) shutil.rmtree(plugin_path) repos.pop(args) self["repos"] = repos return "Plugins unloaded and repo %s removed" % args
def uninstall(self, mess, args): """ uninstall a plugin repository by name. """ if not args.strip(): return "You should have a repo name as argument" repos = self.internal_shelf.get('repos', {}) if not repos.has_key(args): return "This repo is not installed check with !repos the list of installed ones" plugin_path = PLUGIN_DIR + os.sep + args for plugin in get_all_plugins(): if plugin.path.startswith(plugin_path) and hasattr(plugin,'is_activated') and plugin.is_activated: self.send(mess.getFrom(), '/me is unloading plugin %s' % plugin.name) self.deactivate_plugin(plugin.name) shutil.rmtree(plugin_path) repos.pop(args) self.internal_shelf['repos'] = repos return 'Plugins unloaded and repo %s removed' % args
def repos_uninstall(self, mess, args): """ uninstall a plugin repository by name. """ if not args.strip(): return "You should have a repo name as argument" repos = self.get(REPOS, {}) if args not in repos: return "This repo is not installed check with " + self.prefix + "repos the list of installed ones" plugin_path = self.plugin_dir + os.sep + args for plugin in get_all_plugins(): if plugin.path.startswith(plugin_path) and hasattr(plugin, 'is_activated') and plugin.is_activated: self.send(mess.getFrom(), '/me is unloading plugin %s' % plugin.name) self.deactivate_plugin(plugin.name) shutil.rmtree(plugin_path) repos.pop(args) self[REPOS] = repos return 'Plugins unloaded and repo %s removed' % args
def repos_update(self, mess, args): """ update the bot and/or plugins use : !repos update all to update everything or : !repos update core to update only the core or : !repos update repo_name repo_name ... to update selectively some repos """ git_path = which('git') if not git_path: return ('git command not found: You need to have git installed on ' 'your system to be able to install git based plugins.') directories = set() repos = self.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( [self.plugin_dir + os.sep + name for name in repos]) else: directories.update([ self.plugin_dir + os.sep + name for name in set(args).intersection(set(repos)) ]) for d in directories: self.send(mess.frm, "I am updating %s ..." % d, message_type=mess.type) p = subprocess.Popen([git_path, 'pull'], cwd=d, stdout=subprocess.PIPE, stderr=subprocess.PIPE) feedback = p.stdout.read().decode('utf-8') + '\n' + '-' * 50 + '\n' err = p.stderr.read().strip().decode('utf-8') if err: feedback += err + '\n' + '-' * 50 + '\n' dep_err = check_dependencies(d) if dep_err: feedback += dep_err + '\n' if p.wait(): self.send(mess.frm, "Update of %s failed...\n\n%s\n\n resuming..." % (d, feedback), message_type=mess.type) else: self.send(mess.frm, "Update of %s succeeded...\n\n%s\n\n" % (d, feedback), message_type=mess.type) 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: name = plugin.name self.send(mess.frm, '/me is reloading plugin %s' % name) reload_plugin_by_name(plugin.name) self.activate_plugin(plugin.name) self.send(mess.frm, '%s reloaded and reactivated' % name) if core_to_update: self.restart(mess, '') return "You have updated the core, I need to restart." return "Done."