def _pearl(pearl_env: PearlEnvironment, args): command = PearlCommand.from_string(args.command) if hasattr(args, 'packages'): args.packages = _extract_packages(pearl_env, command, args) if command == PearlCommand.INIT: syst.init_pearl(pearl_env, args) elif command == PearlCommand.INSTALL: pack.install_packages(pearl_env, args) elif command == PearlCommand.UPDATE: if not args.packages: syst.update_pearl(pearl_env, args) else: pack.update_packages(pearl_env, args) elif command == PearlCommand.REMOVE: if not args.packages: syst.remove_pearl(pearl_env, args) else: pack.remove_packages(pearl_env, args) elif command == PearlCommand.EMERGE: pack.emerge_packages(pearl_env, args) elif command == PearlCommand.INFO: pack.info_packages(pearl_env, args) elif command == PearlCommand.LIST: pack.list_packages(pearl_env, args) elif command == PearlCommand.SEARCH: pack.list_packages(pearl_env, args) elif command == PearlCommand.CREATE: pack.create_package(pearl_env, args) else: raise ValueError( 'No command specified. Run "pearl --help" for list of commands.')
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_remove_packages_required_installed_packages_raise(tmp_path, required_package_installed, expected_remove_calls): home_dir = create_pearl_home(tmp_path) if required_package_installed: (home_dir / 'packages/repo-test/pkg1').mkdir(parents=True) packages_info = { "repo-test": { "pkg1": { "repo_name": "repo-test", "name": "pkg1", "url": "/blah", "depends": ["repo-test/deppkg1"] }, "deppkg1": { "repo_name": "repo-test", "name": "deppkg1", "url": "/blah", "depends": [] } } } builder = PackageBuilder(home_dir) packages = builder.build_packages(packages_info) pearl_env = PearlEnvironment( home_dir, env_initialized=False ) pearl_env._packages = packages with mock.patch(_MODULE_UNDER_TEST + '.remove_package') as remove_mock: args = PackageArgs(packages=[packages['repo-test']['deppkg1']]) if required_package_installed: with pytest.raises(PackageRequiredByOtherError): remove_packages(pearl_env, args) else: remove_packages(pearl_env, args) assert remove_mock.call_count == expected_remove_calls
def test_remove_packages(tmp_path): home_dir = create_pearl_home(tmp_path) packages_info = { "repo-test": { "pkg1": { "repo_name": "repo-test", "name": "pkg1", "url": "/blah", "depends": ["repo-test/deppkg1"] }, "pkg2": { "repo_name": "repo-test", "name": "pkg2", "url": "/blah", "depends": [] }, "deppkg1": { "repo_name": "repo-test", "name": "deppkg1", "url": "/blah", "depends": [] } } } builder = PackageBuilder(home_dir) packages = builder.build_packages(packages_info) pearl_env = PearlEnvironment( home_dir, env_initialized=False ) pearl_env._packages = packages with mock.patch(_MODULE_UNDER_TEST + '.remove_package') as remove_mock: args = PackageArgs(packages=[packages['repo-test']['pkg1'], packages['repo-test']['pkg2']]) remove_packages(pearl_env, args) remove_mock.assert_has_calls([mock.call(mock.ANY, packages['repo-test']['pkg2'], args), mock.call(mock.ANY, packages['repo-test']['pkg1'], args)])