Example #1
0
    def repos_install(self, mess, args):
        """ install a plugin repository from the given source or a known public repo (see !repos to find those).
        for example from a known repo : !install err-codebot
        for example a git url : [email protected]:gbin/plugin.git
        or an url towards a tar.gz archive : http://www.gootz.net/plugin-latest.tar.gz
        """
        if not args.strip():
            return "You should have an urls/git repo argument"
        if args in KNOWN_PUBLIC_REPOS:
            args = KNOWN_PUBLIC_REPOS[args][0]  # replace it by the url
        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 install git based plugins.'

        if args.endswith('tar.gz'):
            tar = TarFile(fileobj=urlopen(args))
            tar.extractall(path=self.plugin_dir)
            human_name = args.split('/')[-1][:-7]
        else:
            human_name = human_name_for_git_url(args)
            p = subprocess.Popen([git_path, 'clone', args, human_name], cwd=self.plugin_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            feedback = p.stdout.read().decode('utf-8')
            error_feedback = p.stderr.read().decode('utf-8')
            if p.wait():
                return "Could not load this plugin : \n%s\n---\n%s" % (feedback, error_feedback)
        self.add_plugin_repo(human_name, args)
        errors = self.update_dynamic_plugins()
        if errors:
            self.send(mess.getFrom(), 'Some plugins are generating errors:\n' + '\n'.join(errors), message_type=mess.getType())
        else:
            self.send(mess.getFrom(), "A new plugin repository named %s has been installed correctly from %s. Refreshing the plugins commands..." % (human_name, args), message_type=mess.getType())
        self.activate_non_started_plugins()
        return "Plugin reload done."
Example #2
0
    def install(self, mess, args):
        """ install a plugin repository from the given source or a known public repo (see !repos to find those).
        for example from a known repo : !install err-codebot
        for example a git url : [email protected]:gbin/plugin.git
        or an url towards a tar.gz archive : http://www.gootz.net/plugin-latest.tar.gz
        """
        if not args.strip():
            return "You should have an urls/git repo argument"
        if args in KNOWN_PUBLIC_REPOS:
            args = KNOWN_PUBLIC_REPOS[args][0] # replace it by the url
        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 install git based plugins.'

        if args.endswith('tar.gz'):
            tar = TarFile(fileobj=urlopen(args))
            tar.extractall(path= PLUGIN_DIR)
            human_name = args.split('/')[-1][:-7]
        else:
            human_name = human_name_for_git_url(args)
            p = subprocess.Popen([git_path, 'clone', args, human_name], cwd = PLUGIN_DIR, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
            feedback = p.stdout.read()
            error_feedback = p.stderr.read()
            if p.wait():
               return "Could not load this plugin : \n%s\n---\n%s" % (feedback, error_feedback)
        self.add_plugin_repo(human_name, args)
        errors = self.update_dynamic_plugins()
        if errors:
            self.send(mess.getFrom(), 'Some plugins are generating errors:\n' + '\n'.join(errors) , message_type=mess.getType())
        else:
            self.send(mess.getFrom(), "A new plugin repository named %s has been installed correctly from %s. Refreshing the plugins commands..." % (human_name, args), message_type=mess.getType())
        self.activate_non_started_plugins()
        return "Plugin reload done."
Example #3
0
    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."
Example #4
0
    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._bot.get(self._bot.REPOS, {})
        core_to_update = "all" in args or "core" in args
        if core_to_update:
            directories.add(path.dirname(__file__))

        if "all" in args:
            directories.update([path.join(self._bot.plugin_dir, name) for name in repos])
        else:
            directories.update([path.join(self._bot.plugin_dir, 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 self._bot.getAllPlugins():
                        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)
                            self._bot.reload_plugin_by_name(plugin.name)
                            self.send(mess.frm, "%s reloaded and reactivated" % name)
        if core_to_update:
            self.send(mess.frm, "You have updated the core, I need to restart.", message_type=mess.type)
            global_restart()
        return "Done."
Example #5
0
    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."
Example #6
0
    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."
Example #7
0
    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._bot.get(self._bot.REPOS, {})
        core_to_update = 'all' in args or 'core' in args
        if core_to_update:
            directories.add(path.dirname(__file__))

        if 'all' in args:
            directories.update([path.join(self._bot.plugin_dir, name) for name in repos])
        else:
            directories.update([path.join(self._bot.plugin_dir, 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 self._bot.getAllPlugins():
                        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)
                            self._bot.reload_plugin_by_name(plugin.name)
                            self.send(mess.frm, '%s reloaded and reactivated' % name)
        if core_to_update:
            self.send(mess.frm, "You have updated the core, I need to restart.", message_type=mess.type)
            global_restart()
        return "Done."
Example #8
0
    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 = {}
        _installed = self._bot.get_installed_plugin_repos()

        # Fix to migrate exiting plugins into new format
        for short_name, url in _installed.items():
            name = ('/'.join(url.split('/')[-2:])).replace('.git', '')

            t_installed = {name: {
                'path': url,
                'documentation': 'Unavilable',
                'python': None,
                'avatar_url': None,
                }
            }
            repos.update(t_installed)

        core_to_update = 'all' in args or 'core' in args
        if core_to_update:
            directories.add(path.dirname(__file__))

        if 'all' in args:
            directories.update([path.join(self._bot.plugin_dir, name) for name in repos])
        else:
            directories.update([path.join(self._bot.plugin_dir, 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 self._bot.getAllPlugins():
                        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)
                            self._bot.reload_plugin_by_name(plugin.name)
                            self.send(mess.frm, '%s reloaded and reactivated' % name)
        if core_to_update:
            self.send(mess.frm, "You have updated the core, I need to restart.", message_type=mess.type)
            global_restart()
        return "Done."