def test_depends_uninstall(self): deps = DependencyUtils.uninstall(PackageIdentifier.parse_list([]), self.pm.list_installed_packages()) self.__assert_deps(deps, [], InstalledPackage) self.pm.install_packages(PackageIdentifier.parse_list(["container-A_1.0"])) deps = DependencyUtils.uninstall(PackageIdentifier.parse_list(["container-A_1.0"]), self.pm.list_installed_packages()) self.__assert_deps(deps, ["container-A_1.0", "container-C_1.0", "container-B_1.0", "container-E_1.0"], InstalledPackage)
def test_uninstall(self): ipmap = OrderedDict() for ap in DependencyUtils.install( PackageIdentifier.parse_list( ["container-A_1.0", "container-A_2.0"]), APMAP, {}): ipmap[ap.identifier] = IPMAP[ap.identifier] self.assertEqual([ "container-E_1.0", "container-B_1.0", "container-C_1.0", "container-A_1.0", "container-D_1.0", "container-A_2.0" ], deps2strlist(ipmap.values())) deps = DependencyUtils.uninstall( PackageIdentifier.parse_list(["container-A_1.0"]), ipmap) self.assertEqual( ["container-A_1.0", "container-B_1.0", "container-E_1.0"], deps2strlist(deps))
def uninstall_packages(self, pilist: list): """ Remove given package """ with self.application_lock.acquire(): ipmap = self.list_installed_packages() iplist_to_remove = DependencyUtils.uninstall(pilist, ipmap, logger=self.logger) if len(iplist_to_remove) == 0: self.logger.print_default("No package to remove") else: # Confirm text = ", ".join( [str(ip.identifier) for ip in iplist_to_remove]) self.logger.print_quiet( "Packages to uninstall: {packages}".format(packages=text)) self.print_with_confirm(raise_on_decline=True) for ip in iplist_to_remove: if ip.read_only: raise LeafException( "Cannot uninstall system package {ip.identifier}". format(ip=ip)) self.logger.print_default( "Removing {ip.identifier}".format(ip=ip)) self.__execute_steps(ip.identifier, ipmap, StepExecutor.uninstall) self.logger.print_verbose( "Remove folder: {ip.folder}".format(ip=ip)) rmtree_force(ip.folder) del ipmap[ip.identifier] self.logger.print_default("{count} package(s) removed".format( count=len(iplist_to_remove)))
def execute(self, args, uargs): pm = PackageManager() env = None # If the user specified env values, build a complete env if args.custom_envlist is not None: env = Environment.build( pm.build_builtin_environment(), pm.build_user_environment(), Environment("Custom env", env_list_to_map(args.custom_envlist))) items = None if args.dependency_type == "available": items = DependencyUtils.install(PackageIdentifier.parse_list( args.packages), pm.list_available_packages(), {}, env=env) elif args.dependency_type == "install": items = DependencyUtils.install(PackageIdentifier.parse_list( args.packages), pm.list_available_packages(), pm.list_installed_packages(), env=env) elif args.dependency_type == "installed": items = DependencyUtils.installed(PackageIdentifier.parse_list( args.packages), pm.list_installed_packages(), env=env, ignore_unknown=True) elif args.dependency_type == "uninstall": items = DependencyUtils.uninstall(PackageIdentifier.parse_list( args.packages), pm.list_installed_packages(), env=env) elif args.dependency_type == "prereq": items = DependencyUtils.prereq(PackageIdentifier.parse_list( args.packages), pm.list_available_packages(), pm.list_installed_packages(), env=env) elif args.dependency_type == "upgrade": items, _ = DependencyUtils.upgrade( None if len(args.packages) == 0 else args.packages, pm.list_available_packages(), pm.list_installed_packages(), env=env) elif args.dependency_type == "rdepends": mfmap = OrderedDict() mfmap.update( DependencyUtils.rdepends(PackageIdentifier.parse_list( args.packages), pm.list_available_packages(), env=env)) mfmap.update( DependencyUtils.rdepends(PackageIdentifier.parse_list( args.packages), pm.list_installed_packages(), env=env)) items = mfmap.values() else: raise ValueError() rend = ManifestListRenderer() rend.extend(items) pm.print_renderer(rend)