コード例 #1
0
    def prereq(pilist: list,
               apmap: dict,
               ipmap: dict,
               env: Environment = None):
        """
        Return the list of prereq packages to install
        Packages are sorted in alpha order.
        Returns a list of AvailablePackages
        """
        # All available packages
        mfmap = reduce(lambda a, b: a.update(b) or a,
                       [apmap or {}, ipmap or {}], {})

        # Get the list of prereq
        prereq_pilist = []
        for pi in pilist:
            mf = find_manifest(pi, mfmap)
            for pis in mf.requires_packages:
                prereq_pi = PackageIdentifier.parse(pis)
                if prereq_pi not in prereq_pilist:
                    prereq_pilist.append(prereq_pi)

        # Compute prereq dependencies
        out = []
        DependencyUtils.__build_tree(prereq_pilist, mfmap, out, env=env)
        return out
コード例 #2
0
ファイル: packages.py プロジェクト: sam974/leaf
 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)
コード例 #3
0
ファイル: steps.py プロジェクト: vutruong1711/leaf
 def get_value(self, var: str, pis: str):
     pkg = None
     if pis is None:
         # No PI specified means current package
         pkg = self.__current_package
     else:
         pkg = find_manifest(PackageIdentifier.parse(pis), self.__all_packages, ignore_unknown=True)
     if pkg is not None:
         if var == "NAME":
             return pkg.name
         if var == "VERSION":
             return pkg.version
         if var == "DIR":
             return str(pkg.folder)
コード例 #4
0
    def __build_tree(pilist: list,
                     mfmap: dict,
                     out: list,
                     env: Environment = None,
                     only_keep_latest: bool = False,
                     ignored_pilist: list = None,
                     ignore_unknown: bool = False):
        """
        Build a manifest list of given PackageIdentifiers and its dependecies
        @return: Manifest list
        """
        if ignored_pilist is None:
            ignored_pilist = []
        for pi in pilist:
            if pi not in ignored_pilist:
                ignored_pilist.append(pi)
                mf = find_manifest(pi, mfmap, ignore_unknown=ignore_unknown)
                if mf is not None and mf not in out:
                    # Begin by adding dependencies
                    DependencyUtils.__build_tree(mf.get_depends_from_env(env),
                                                 mfmap,
                                                 out,
                                                 env=env,
                                                 ignored_pilist=ignored_pilist,
                                                 ignore_unknown=ignore_unknown)
                    out.append(mf)

        if only_keep_latest:
            # Create a MF dict overriding package to latest version previously
            # computed
            alt_mfmap = {}
            for pi in mfmap:
                latest_mf = None
                for mf in out:
                    if pi.name == mf.name:
                        if latest_mf is None or mf.identifier > latest_mf.identifier:
                            latest_mf = mf
                alt_mfmap[pi] = latest_mf or mfmap[pi]
            # Reset out
            del out[:]
            # Reinvoke and give latest versions,
            # NB reset ignored_pilist to restart algo
            DependencyUtils.__build_tree(pilist,
                                         alt_mfmap,
                                         out,
                                         env=env,
                                         ignore_unknown=ignore_unknown)
コード例 #5
0
ファイル: packages.py プロジェクト: NicolasLambert/leaf
    def install_prereq(self,
                       pilist: list,
                       tmp_install_folder: Path,
                       apmap: dict = None,
                       env: Environment = None,
                       raise_on_error: bool = True):
        """
        Install given prereg available package in alternative root folder
        @return: error count
        """
        if apmap is None:
            apmap = self.list_available_packages()

        # Get packages to install
        aplist = [find_manifest(pi, apmap) for pi in pilist]

        errors = 0
        if len(aplist) > 0:
            self.logger.print_verbose(
                "Installing {count} pre-required package(s) in {folder}".
                format(count=len(aplist), folder=tmp_install_folder))
            if env is None:
                env = Environment.build(self.build_builtin_environment(),
                                        self.build_user_environment())
            env.append(
                Environment("Prereq",
                            {"LEAF_PREREQ_ROOT": tmp_install_folder}))
            for prereqap in aplist:
                try:
                    prereqla = self.__download_ap(prereqap)
                    prereqip = self.__extract_artifact(
                        prereqla,
                        env,
                        tmp_install_folder,
                        keep_folder_on_error=True)
                    self.logger.print_verbose(
                        "Prereq package {ip.identifier} is OK".format(
                            ip=prereqip))
                except Exception as e:
                    if raise_on_error:
                        raise e
                    self.logger.print_verbose(
                        "Prereq package {ap.identifier} has error: {error}".
                        format(ap=prereqap, error=e))
                    errors += 1
        return errors
コード例 #6
0
 def prereq(pilist: list,
            apmap: dict,
            ipmap: dict,
            env: Environment = None):
     """
     Return the list of prereq packages to install
     Packages are sorted in alpha order.
     Returns a list of AvailablePackages
     """
     out = []
     # First get the install tree
     aplist = DependencyUtils.install(pilist, apmap, ipmap, env=env)
     # Get all prereq PI and find corresponding AP
     for ap in aplist:
         for pi in map(PackageIdentifier.parse, ap.requires_packages):
             out.append(find_manifest(pi, apmap))
     # sort alphabetically and ensure no dupplicates
     out = list(sorted(set(out), key=IDENTIFIER_GETTER))
     return out
コード例 #7
0
ファイル: packages.py プロジェクト: NicolasLambert/leaf
 def build_packages_environment(self, items: list, ipmap=None):
     """
     Get the env vars declared by given packages
     @param items: a list of InstalledPackage or PackageIdentifier
     """
     ipmap = ipmap or self.list_installed_packages()
     out = Environment()
     for item in items:
         ip = None
         if isinstance(item, InstalledPackage):
             ip = item
         elif isinstance(item, PackageIdentifier):
             ip = None
             if is_latest_package(item):
                 ip = find_manifest(item, ipmap)
             else:
                 ip = ipmap.get(item)
             if ip is None:
                 raise InvalidPackageNameException(item)
         else:
             raise InvalidPackageNameException(item)
         vr = VariableResolver(ip, ipmap.values())
         out.append(ip.build_environment(vr=vr.resolve))
     return out