def test_depends_installed(self): deps = DependencyUtils.installed(PackageIdentifier.parse_list(["container-A_1.0"]), self.pm.list_installed_packages(), ignore_unknown=True) self.__assert_deps(deps, [], InstalledPackage) self.pm.install_packages(PackageIdentifier.parse_list(["container-A_1.0"])) deps = DependencyUtils.installed(PackageIdentifier.parse_list(["container-A_1.0"]), self.pm.list_installed_packages()) self.__assert_deps(deps, ["container-E_1.0", "container-B_1.0", "container-C_1.0", "container-A_1.0"], InstalledPackage)
def __execute_steps(self, pi: PackageIdentifier, ipmap: dict, se_func: callable, env: Environment = None): # Find the package ip = find_manifest(pi, ipmap) # The environment if env is None: env = Environment.build(self.build_builtin_environment(), self.build_user_environment()) # build the dependencies deps = DependencyUtils.installed([pi], ipmap, env=env, ignore_unknown=True) # Update env env.append(self.build_packages_environment(deps)) # Fix PREREQ_ROOT env.set_variable("LEAF_PREREQ_ROOT", self.install_folder) # The Variable resolver vr = VariableResolver(ip, ipmap.values()) # Execute steps se = StepExecutor(self.logger, ip, vr, env=env) se_func(se)
def get_profile_dependencies(self, profile, ipmap=None): """ Returns all latest packages needed by a profile """ return DependencyUtils.installed( profile.packages, ipmap or self.list_installed_packages(), only_keep_latest=True, env=self.build_pf_environment(profile))
def test_latest_strategy(self): deps = DependencyUtils.installed( PackageIdentifier.parse_list( ["container-A_1.0", "container-A_2.0"]), IPMAP) 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" ], list(map(str, map(IDENTIFIER_GETTER, deps))), ) deps = DependencyUtils.installed(PackageIdentifier.parse_list( ["container-A_1.0", "container-A_2.0"]), IPMAP, only_keep_latest=True) self.assertEqual( ["container-C_1.0", "container-D_1.0", "container-A_2.0"], list(map(str, map(IDENTIFIER_GETTER, deps))))
def execute(self, args, uargs): wm = self.get_workspacemanager(check_initialized=False) ipmap = wm.list_installed_packages() searching_iplist = None env = None if args.package is not None: # User forces the package env = Environment.build(wm.build_builtin_environment(), wm.build_user_environment()) searching_iplist = DependencyUtils.installed([args.package], ipmap, env=env) env.append(wm.build_packages_environment(searching_iplist)) elif wm.is_initialized: # We are in a workspace, use the current profile pfname = wm.current_profile_name profile = wm.get_profile(pfname) wm.is_profile_sync(profile, raise_if_not_sync=True) searching_iplist = wm.get_profile_dependencies(profile) env = wm.build_full_environment(profile) else: # Use installed packages searching_iplist = sorted(ipmap.values(), key=IDENTIFIER_GETTER) # Execute if args.binary is None: # Print mode scope = "installed packages" if args.package is not None: scope = args.package elif wm.is_initialized: scope = "workspace" rend = EntrypointListRenderer(scope) rend.extend(searching_iplist) wm.print_renderer(rend, verbosity=Verbosity.QUIET if args.oneline else Verbosity.DEFAULT) elif args.oneline: # User gave BIN and --oneline raise LeafException( "You must specify a binary or '--oneline', not both", hints=[ "Run 'leaf run --oneline' to list all binaries", "Run 'leaf run {bin} -- --oneline {uargs}' pass --oneline to the binary" .format(bin=args.binary, uargs=" ".join(uargs)), ], ) else: # Search entry point candidate_ip = None for ip in searching_iplist: if args.binary in ip.binaries: if candidate_ip is None: candidate_ip = ip elif candidate_ip.name != ip.name: raise LeafException( "Binary {bin} is declared by multiple packages". format(bin=args.binary)) elif ip.identifier > candidate_ip.identifier: candidate_ip = ip if candidate_ip is None: raise LeafException( "Cannot find binary {bin}".format(bin=args.binary)) if env is None: env = Environment.build(wm.build_builtin_environment(), wm.build_user_environment()) env.append( wm.build_packages_environment( DependencyUtils.installed([candidate_ip.identifier], ipmap=ipmap, env=env))) ep = candidate_ip.binaries[args.binary] vr = VariableResolver(candidate_ip, ipmap.values()) return execute_command(vr.resolve(ep.command), *uargs, print_stdout=True, env=env)
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): wm = self.get_workspacemanager(check_initialized=False) ipmap = wm.list_installed_packages() searching_iplist = None if args.package is not None: # User forces the package searching_iplist = DependencyUtils.installed( [args.package], ipmap, env=Environment.build(wm.build_builtin_environment(), wm.build_user_environment())) else: # Use installed packages searching_iplist = keep_latest_mf(ipmap.values()) topics = self.get_topics(searching_iplist) if args.topic is not None: topic = self.find_topic(topics, args.topic) fmt = args.format if fmt is None: # No format given if LeafSettings.HELP_DEFAULT_FORMAT.value in topic.resources.keys( ): # Default format is available fmt = LeafSettings.HELP_DEFAULT_FORMAT.value elif len(topic.resources.keys()) == 1: # Only one format available fmt = next(iter(topic.resources.keys())) if fmt is None or fmt not in topic.resources.keys(): # Ensure that this topic is available for needed format raise LeafException( "You need to specify a format for topic '{topic}'".format( topic=args.topic), hints=[ "For example 'leaf help --format {fmt} {topic}'". format(fmt=fmt, topic=args.topic) for fmt in topic.resources.keys() ], ) # Resolve resource path since it can contain @{} variables resource = VariableResolver(topic.installed_package, ipmap.values()).resolve( topic.resources[fmt]) if fmt == "man": # If format is 'man', use manpage reader command = [ "man", "-P", "cat" ] if LeafSettings.NON_INTERACTIVE.as_boolean() else ["man"] command.append(resource) subprocess.check_call(command) else: # Use default resource handler subprocess.check_call( [LeafSettings.HELP_DEFAULT_OPEN.value, resource]) else: # Print mode scope = "installed packages" if args.package is not None: scope = args.package rend = HelpTopicListRenderer(scope, filter_format=args.format) rend.extend(searching_iplist) wm.print_renderer(rend)