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)
def update(self, msg, matches): repo_name = CENTRAL_REPO_NAME url = CENTRAL_REPO_URL pkg_repo_dir = Path(PKG_REPO_DIR) if not pkg_repo_dir.exists(): pkg_repo_dir.mkdir(parents=True) 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))
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)
def install(self, msg, matches): if not self.repos: self.respond_to_msg( msg, "Cannot locate repo. Try running \"!pkg update\"") repo_name = CENTRAL_REPO_NAME if not path.exists(PKG_INSTALL_DIR): os.makedirs(PKG_INSTALL_DIR) for pkg_name in matches.group(2).split(): url = None pkg_data = None if urlparse(matches.group(2)).scheme in ["http", "https"]: url = pkg_name else: 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)) return url = pkg_data["repo"] if not url: self.respond_to_msg( msg, "Invalid package name or url: {}".format(pkg_name)) gs = git.clone(url, pkg_data["pkg_name"], cwd=PKG_INSTALL_DIR) if gs.has_error(): self.respond_to_msg( msg, "Error installing package \"{}\"\n{}{}".format( pkg_name, gs.stdout, gs.stderr)) return pkg_req_path = self._pkg_requirements_path(pkg_name) if os.path.exists(pkg_req_path): pip.main(['install', '-r', 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))
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)
def install(self, msg, matches): if not self.repos: self.respond_to_msg(msg, "Cannot locate repo. Try running \"!pkg update\"") repo_name = CENTRAL_REPO_NAME if not path.exists(PKG_INSTALL_DIR): os.makedirs(PKG_INSTALL_DIR) for pkg_name in matches.group(2).split(): url = None pkg_data = None if urlparse(matches.group(2)).scheme in ["http", "https"]: url = pkg_name else: 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)) return url = pkg_data["repo"] if not url: self.respond_to_msg(msg, "Invalid package name or url: {}".format(pkg_name)) gs = git.clone(url, pkg_data["pkg_name"], cwd=PKG_INSTALL_DIR) if gs.has_error(): self.respond_to_msg(msg, "Error installing package \"{}\"\n{}{}".format(pkg_name, gs.stdout, gs.stderr)) return pkg_req_path = self._pkg_requirements_path(pkg_name) if os.path.exists(pkg_req_path): pip.main(['install', '-r', 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))
def update(self, msg, matches): repo_name = CENTRAL_REPO_NAME url = CENTRAL_REPO_URL pkg_repo_dir = Path(PKG_REPO_DIR) if not pkg_repo_dir.exists(): pkg_repo_dir.mkdir(parents=True) 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))