예제 #1
0
    def update(self, msg, matches):
        repos = self._get_repos_from_config()

        if not repos:
            self.respond_to_msg(msg, "Warning: there are no repos in the configuration")
            return

        pkg_repo_dir = Path(PKG_REPO_DIR)
        if not pkg_repo_dir.exists():
            pkg_repo_dir.mkdir(parents=True)

        for repo_name, url in repos.items():
            gs = None
            if repo_name not in self._installed_repos():
                gs = git.clone(url, directory=repo_name, cwd=PKG_REPO_DIR)
            else:
                repo_path = self._repo_path(repo_name)
                git.reset(cwd=repo_path, hard=True)
                gs = git.pull(cwd=repo_path)

            if not gs:
                self.respond_to_msg(msg, "Unkown error updating repo: {}".format(repo_name))
                return

            if not gs.has_error():
                self._reload_repos(msg)

            self.respond_to_msg(msg, "{}: {}{}".format(repo_name, gs.stdout, gs.stderr))
예제 #2
0
    def install(self, msg, matches):
        pkg_name = matches.groupdict()['pkg_name']
        location = matches.groupdict()['location']

        pkg_inst_path = Path(PKG_INSTALL_DIR)
        if not pkg_inst_path.exists():
            pkg_inst_path.mkdir(parents=True)

        destination = self._pkg_repo_path(pkg_name)

        if not location.startswith("http"):
            result = self._copy_directory(location, destination)
            self.respond_to_msg(msg, result)

        else:
            gs = git.clone(location, pkg_name, cwd=str(pkg_inst_path))
            if gs.has_error():
                self.respond_to_msg(msg, "Error installing package \"{}\"\n{}{}".format(pkg_name, gs.stdout, gs.stderr))
                return

            pkg_req_path = pkg_inst_path / pkg_name / "repository" / "requirements.txt"
            # print('\n\n{}\n\n'.format(pkg_req_path))
            if pkg_req_path.exists():
                pip.main(['install', '--upgrade', '-r', str(pkg_req_path)])

            self.reload_plugins()

            self.plugin_manager.collectPlugins()
            self.respond_to_msg(msg, "{}{}\nSuccessfully installed package: {}".format(gs.stdout, gs.stderr, pkg_name))
예제 #3
0
파일: unittests.py 프로젝트: Thom7/telex
 def test_clone_to_empty_with_name(self):
     with TemporaryDirectory() as d:
         # clone into specified directory
         gs = git.clone(REPO_URL, cwd=d, directory=REPO_NAME)
         self.assertIsNotNone(gs)
         self.assertTrue(exists(join(d, REPO_NAME, ".git")))
         self.assertEqual(gs.exit_status, 0)
예제 #4
0
    def update(self, msg, matches):
        repos = self._get_repos_from_config()

        if not repos:
            self.respond_to_msg(msg, "Warning: there are no repos in the configuration")
            return

        pkg_repo_dir = Path(PKG_REPO_DIR)
        if not pkg_repo_dir.exists():
            pkg_repo_dir.mkdir(parents=True)

        for repo_name, url in repos.items():
            gs = None
            if repo_name not in self._installed_repos():
                gs = git.clone(url, directory=repo_name, cwd=PKG_REPO_DIR)
            else:
                repo_path = self._repo_path(repo_name)
                git.reset(cwd=repo_path, hard=True)
                gs = git.pull(cwd=repo_path)

            if not gs:
                self.respond_to_msg(msg, "Unkown error updating repo: {}".format(repo_name))
                return

            if not gs.has_error():
                self._reload_repos(msg)

            self.respond_to_msg(msg, "{}: {}{}".format(repo_name, gs.stdout, gs.stderr))
예제 #5
0
    def install(self, msg, matches):
        if not self.repos:
            self.respond_to_msg(msg, "Cannot locate repo. Try running \"!pkg update\"")
            return

        repo_name = matches.groupdict()['repo_name']
        pkg_name = matches.groupdict()['pkg_name']

        if not repo_name:
            repos_with_pkg = []
            for r in self.repos:
                for pkg in self.repos[r]['packages']:
                    if pkg['pkg_name'] == pkg_name:
                        repos_with_pkg.append(r)

            if not repos_with_pkg:
                self.respond_to_msg(msg, 'Cannot find pkg "{}" in any repos.\nTry running "!pkg update"'.format(pkg_name))
                return

            if len(repos_with_pkg) > 1:
                self.respond_to_msg(msg, 'Package "{}" found in multiple repos. Please specify repo using:\n <repo_name>/<pkg_name>\nRepos with package: {}'.format(pkg_name, ', '.join(repos_with_pkg)))
                return

            repo_name = repos_with_pkg[0]

        pkg_data = self._pkg_data_from_repo(pkg_name, repo_name)
        if not pkg_data:
            self.respond_to_msg(msg, 'Package "{}" not found in repository "{}"'.format(pkg_name, repo_name))
            return
    
        url = pkg_data["repo"]
        if not url:
            self.respond_to_msg(msg, 'Error: unable to retrieve url for package "{}"'.format(pkg_name))
            return

        pkg_inst_path = Path(PKG_INSTALL_DIR)
        if not pkg_inst_path.exists():
            pkg_inst_path.mkdir(parents=True)

        gs = git.clone(url, pkg_data["pkg_name"], cwd=str(pkg_inst_path))
        if gs.has_error():
            self.respond_to_msg(msg, "Error installing package \"{}\"\n{}{}".format(pkg_name, gs.stdout, gs.stderr))
            return

        pkg_req_path = pkg_inst_path / pkg_name / "repository" / "requirements.txt"
        print('\n\n{}\n\n'.format(pkg_req_path))
        if pkg_req_path.exists():
            pip.main(['install', '--upgrade', '-r', str(pkg_req_path)])

        self.reload_plugins()
        for plugin_name in pkg_data.get("default_enable", []):
            self.plugin_manager.activatePluginByName(plugin_name)

        self.plugin_manager.collectPlugins()
        self.respond_to_msg(msg, "{}{}\nSuccessfully installed package: {}".format(gs.stdout, gs.stderr, pkg_name))
예제 #6
0
    def install(self, msg, matches):
        if not self.repos:
            self.respond_to_msg(msg, "Cannot locate repo. Try running \"{prefix}pkg update\"".replace('{prefix}', self.bot.pfx))
            return

        repo_name = matches.groupdict()['repo_name']
        pkg_name = matches.groupdict()['pkg_name']

        if not repo_name:
            repos_with_pkg = []
            for r in self.repos:
                for pkg in self.repos[r]['packages']:
                    if pkg['pkg_name'] == pkg_name:
                        repos_with_pkg.append(r)

            if not repos_with_pkg:
                self.respond_to_msg(msg, 'Cannot find pkg "{}" in any repos.\nTry running "{prefix}pkg update"'.format(pkg_name).replace('{prefix}', self.bot.pfx))
                return

            if len(repos_with_pkg) > 1:
                self.respond_to_msg(msg, 'Package "{}" found in multiple repos. Please specify repo using:\n <repo_name>/<pkg_name>\nRepos with package: {}'.format(pkg_name, ', '.join(repos_with_pkg)))
                return

            repo_name = repos_with_pkg[0]

        pkg_data = self._pkg_data_from_repo(pkg_name, repo_name)
        if not pkg_data:
            self.respond_to_msg(msg, 'Package "{}" not found in repository "{}"'.format(pkg_name, repo_name))
            return
    
        url = pkg_data["repo"]
        if not url:
            self.respond_to_msg(msg, 'Error: unable to retrieve url for package "{}"'.format(pkg_name))
            return

        pkg_inst_path = Path(PKG_INSTALL_DIR)
        if not pkg_inst_path.exists():
            pkg_inst_path.mkdir(parents=True)

        gs = git.clone(url, pkg_data["pkg_name"], cwd=str(pkg_inst_path))
        if gs.has_error():
            self.respond_to_msg(msg, "Error installing package \"{}\"\n{}{}".format(pkg_name, gs.stdout, gs.stderr))
            return

        pkg_req_path = pkg_inst_path / pkg_name / "repository" / "requirements.txt"
        print('\n\n{}\n\n'.format(pkg_req_path))
        if pkg_req_path.exists():
            pip.main(['install', '--upgrade', '-r', str(pkg_req_path)])

        self.reload_plugins()
        for plugin_name in pkg_data.get("default_enable", []):
            self.plugin_manager.activatePluginByName(plugin_name)

        self.plugin_manager.collectPlugins()
        self.respond_to_msg(msg, "{}{}\nSuccessfully installed package: {}".format(gs.stdout, gs.stderr, pkg_name))
예제 #7
0
파일: unittests.py 프로젝트: Thom7/telex
    def test_pull_up_to_date(self):
        with TemporaryDirectory() as d:
            # clone repo
            gs = git.clone(REPO_URL, cwd=d, directory=REPO_NAME)
            self.assertIsNotNone(gs)
            self.assertTrue(exists(join(d, REPO_NAME, ".git")))
            self.assertEqual(gs.exit_status, 0)

            # pull while on latest revision
            gs = git.pull(cwd=join(d, REPO_NAME))
            self.assertIsNotNone(gs)
            self.assertEqual(gs.exit_status, 0)
예제 #8
0
파일: unittests.py 프로젝트: Thom7/telex
    def test_pull_out_of_date(self):
        with TemporaryDirectory() as d:
            # Clone a repo
            gs = git.clone(REPO_URL, cwd=d, directory=REPO_NAME)
            self.assertIsNotNone(gs)
            self.assertEqual(gs.exit_status, 0)

            # Revert to the initial commit
            gs = git.reset(cwd=join(d, REPO_NAME), hard=True, commit="6f72f1ad1589f73d62165e19df873c59e829e1dd")
            self.assertIsNotNone(gs)
            self.assertEqual(gs.exit_status, 0)

            # Use pull to get update to the latest commit
            gs = git.pull(cwd=join(d, REPO_NAME))
            self.assertIsNotNone(gs)
            self.assertEqual(gs.exit_status, 0)