def test_upgrade(self): ideps, udeps = DependencyUtils.upgrade(None, APMAP, filtermap(IPMAP, "upgrade_1.0")) self.assertEqual([], [str(mf.identifier) for mf in ideps]) self.assertEqual([], [str(mf.identifier) for mf in udeps]) ideps, udeps = DependencyUtils.upgrade( None, APMAP, filtermap(IPMAP, "upgrade_1.0", "upgrade_1.1", "upgrade_1.2")) self.assertEqual(["upgrade_2.0"], [str(mf.identifier) for mf in ideps]) self.assertEqual(["upgrade_1.1", "upgrade_1.2"], [str(mf.identifier) for mf in udeps])
def execute(self, args, uargs): pm = PackageManager() env = Environment.build(pm.build_builtin_environment(), pm.build_user_environment()) install_list, uninstall_list = DependencyUtils.upgrade( None if len(args.packages) == 0 else args.packages, pm.list_available_packages(), pm.list_installed_packages(), env=env) pm.logger.print_verbose( "{count} package(s) to be upgraded: {text}".format( count=len(install_list), text=" ".join([str(ap.identifier) for ap in install_list]))) if args.clean: pm.logger.print_verbose( "{count} package(s) to be removed: {text}".format( count=len(uninstall_list), text=" ".join( [str(ip.identifier) for ip in uninstall_list]))) if len(install_list) == 0: pm.logger.print_default("No package to upgrade") else: pm.install_packages(map(IDENTIFIER_GETTER, install_list), env=env) if len(uninstall_list) > 0: if args.clean: pm.uninstall_packages( map(IDENTIFIER_GETTER, uninstall_list)) else: pm.logger.print_default( "These packages can be removed:", " ".join([str(ip.identifier) for ip in uninstall_list]))
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)
def execute(self, args, uargs): pm = PackageManager() wm = self.get_workspacemanager() profilename = wm.current_profile_name profile = wm.get_profile(profilename) env = Environment.build(pm.build_builtin_environment(), pm.build_user_environment()) install_list, upgraded_list = DependencyUtils.upgrade( None if len(args.packages) == 0 else args.packages, pm.list_available_packages(), pm.list_installed_packages(), env=env) pm.logger.print_verbose( "{count} package(s) to be upgraded: {text}".format( count=len(install_list), text=" ".join([str(ap.identifier) for ap in install_list]))) if args.clean: pm.logger.print_verbose( "{count} package(s) to be removed: {text}".format( count=len(upgraded_list), text=" ".join([str(ip.identifier) for ip in upgraded_list]))) if len(install_list) == 0: pm.logger.print_default("No package to upgrade") else: pm.install_packages(map(IDENTIFIER_GETTER, install_list), env=env) if len(upgraded_list) > 0: if args.clean: pm.uninstall_packages(map(IDENTIFIER_GETTER, upgraded_list)) else: pm.logger.print_default( "Packages upgraded:", " ".join([str(ip.identifier) for ip in upgraded_list])) pm.logger.print_default( 'Hint: Use "leaf profile config -p {PACKAGENAME}" to add these packages to your workspace profile' ) update_pilist = install_list profile_pkg_map = profile.pkg_map installed_packages = group_package_identifiers_by_name( wm.list_installed_packages()) pkg_list = args.packages if args.packages else profile_pkg_map.keys() for pkg in pkg_list: pi = None if pkg in installed_packages.keys(): # Get latest version pi = installed_packages[pkg][-1] if pi is not None and pi not in update_pilist: # Get PI in profile previous_pi = PackageIdentifier(pi.name, profile_pkg_map[ pi.name]) if pi.name in profile_pkg_map else None if previous_pi is None: # Package is not in profile yet, add it update_pilist.append(pi) elif previous_pi != pi: # Package is already in profile with a different version, update it update_pilist.append(pi) else: # Package is already in profile with same version, do nothing pass if len(update_pilist) == 0: pm.logger.print_default( "Packages are already in profile with same version") else: pm.logger.print_default( "Packages to be updated in profile:", " ".join([str(pi) for pi in update_pilist])) profile.add_packages(update_pilist) wm.update_profile(profile)