def remove_pearl(pearl_env: PearlEnvironment, args: Namespace): """ Removes completely the Pearl environment. """ for repo_name, repo_packages in pearl_env.packages.items(): if ask(f"Are you sure to REMOVE all the installed packages in {repo_name} repository?", yes_as_default_answer=False, no_confirm=args.no_confirm): package_list = [] for _, package in repo_packages.items(): if package.is_installed(): package_list.append(package) args.packages = package_list remove_packages(pearl_env, args=args) if ask("Are you sure to REMOVE all the Pearl hooks?", yes_as_default_answer=False, no_confirm=args.no_confirm): unapply(f"source {pearl_env.home}/boot/sh/pearl.sh", f"{os.environ['HOME']}/.bashrc") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Deactivated Pearl for Bash') unapply(f"source {pearl_env.home}/boot/sh/pearl.sh", f"{os.environ['HOME']}/.zshrc") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Deactivated Pearl for Zsh') unapply(f"source {pearl_env.home}/boot/fish/pearl.fish", f"{os.environ['HOME']}/.config/fish/config.fish") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Deactivated Pearl for Fish shell') unapply(f"source {pearl_env.home}/boot/vim/pearl.vim", f"{os.environ['HOME']}/.vimrc") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Deactivated Pearl for Vim editor') unapply(f"(load-file \"{pearl_env.home}/boot/emacs/pearl.el\")", f"{os.environ['HOME']}/.emacs") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Deactivated Pearl for Emacs editor') if ask("Are you sure to REMOVE the Pearl config $PEARL_HOME directory (NOT RECOMMENDED)?", yes_as_default_answer=False, no_confirm=args.no_confirm): shutil.rmtree(str(pearl_env.home))
def test_unapply_dir_and_file_not_exist(tmp_path): line = 'Add this line' unapply(line, str(tmp_path / 'mydir/file')) assert not (tmp_path / 'file').exists()
def test_unapply(line, file_content, expected_result, tmp_path): (tmp_path / 'file').write_text(file_content) unapply(line, str(tmp_path / 'file')) assert (tmp_path / 'file').read_text() == expected_result