def verify_can_push_repo_to_remote(self): """Verifies that one can push the local module to the remote server. When :meth:`push_repo_to_remote` is called, if the boolean value `_can_push_repo_to_remote` is False, this method is run to make sure that :meth:`push_repo_to_remote` can operate completely. This method also sets the `_can_push_repo_to_remote` attribute to True so it can be run separately before :meth:`push_repo_to_remote`. This method will fail (raise a VerificationError) if: - The local module does not exist - The local module is not a git repository - There is a naming conflict with the remote server Raises: :class:`~dls_ade.exceptions.VerificationError`: Local repository \ cannot be pushed to remote. """ if self._can_push_repo_to_remote: return self._can_push_repo_to_remote = True err_list = [] if not os.path.exists(self.abs_module_path): err_list.append("Directory {dir:s} does not exist.") else: mod_dir_is_repo = vcs_git.is_local_repo_root(self.abs_module_path) if not mod_dir_is_repo: err_list.append("Directory {dir:s} is not a git repository. " "Unable to push to remote repository.") err_list = [err.format(dir=self._module_path) for err in err_list] # This allows us to retain the remote_repo_valid error message if not self._remote_repo_valid: try: self.verify_remote_repo() except VerificationError as e: err_list.append(str(e)) if err_list: self._can_push_repo_to_remote = False raise VerificationError("\n".join(err_list))
def delete_temp_repo(local_repo_path): """Delete a repository in a temporary directory. Args: local_repo_path: The path to the temporary directory. Raises: :class:`.TempdirError`: If the path given is not a temporary folder. :class:`.TempdirError`: If the path given is not for a git repository. """ if not os.path.realpath(local_repo_path).startswith(tempfile.gettempdir()): err_message = ("{local_repo_path:s} is not a temporary folder, cannot " "delete.") raise TempdirError(err_message.format(local_repo_path=local_repo_path)) if not vcs_git.is_local_repo_root(local_repo_path): err_message = ("{local_repo_path:s} is not a git root directory, " "cannot delete.") raise TempdirError(err_message.format(local_repo_path=local_repo_path)) shutil.rmtree(local_repo_path)
def delete_temp_repo(local_repo_path): """Delete a repository in a temporary directory. Args: local_repo_path: The path to the temporary directory. Raises: :class:`.TempdirError`: If the path given is not a temporary folder. :class:`.TempdirError`: If the path given is not for a git repository. """ if not os.path.realpath(local_repo_path).startswith(tempfile.gettempdir()): err_message = ("{local_repo_path:s} is not a temporary folder, cannot " "delete.") raise TempdirError(err_message.format( local_repo_path=local_repo_path)) if not vcs_git.is_local_repo_root(local_repo_path): err_message = ("{local_repo_path:s} is not a git root directory, " "cannot delete.") raise TempdirError(err_message.format( local_repo_path=local_repo_path)) shutil.rmtree(local_repo_path)