Beispiel #1
0
    def Filter(log: Log, topLevelPackage: Package,
               requestedPackages: Optional[List[Package]],
               packageFilters: PackageFilters) -> List[Package]:
        """ Filter the package list based
            - Required packages by the requested packages (if requestedPackages isnt None)
            - If there is executeables then chose those that implement the required features in requiredFeatureNameList
            - the available features from featureNameList
            - the available extensions from extensionNameList
            - if they are supported on the platform
        """
        resolvedBuildOrder = topLevelPackage.ResolvedBuildOrder
        requirements = RequirementFilter.GetRequirementList(
            topLevelPackage, None)
        requirementTree = RequirementTree(requirements)

        # Smart expand the input lists
        # - First we add all parent features automatically to ensure the feature list is complete
        useStrictFeatureWarning = requestedPackages is None or len(
            requestedPackages) <= 0
        featureNameList2 = PackageFilter.__AddParentFeatures(
            log, packageFilters.FeatureNameList, requirementTree,
            useStrictFeatureWarning)
        extensionNameList = packageFilters.ExtensionNameList
        if not packageFilters.ExtensionNameList.AllowAllExtensions:
            # Filter extensions by available features
            extensionNameList = PackageFilter.__FilterExtensionsByAvailableFeatures(
                log, featureNameList2, extensionNameList)
            requirementTree.SetExtensionSupport(log, extensionNameList)

        # Try to determine what the user is interested in building
        requestedPackagesInOrder = PackageFilter.__DetermineActualUserBuildRequest(
            resolvedBuildOrder, requestedPackages)

        # Remove recipe packages
        requestedPackagesInOrder = PackageFilter.__FiltersRecipePackages(
            log, requestedPackagesInOrder)

        # Remove packages based on the users required features request
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByRequiredFeature(
            log, requestedPackagesInOrder,
            packageFilters.RequiredFeatureNameList)
        # Remove packages based on the available features (remove all packages that can't be build due to missing features)
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByFeatures(
            log, requestedPackagesInOrder, featureNameList2)
        # Remove packages based on the available extensions (remove all packages that can't be build due missing extensions)
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByExtensions(
            log, requestedPackagesInOrder, extensionNameList, featureNameList2,
            requirementTree)
        # Remove packages that are not supported on this platform
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesBySupported(
            log, requestedPackagesInOrder)
        # Now that we have a filtered list of desired packages, extend it to include all required packages
        return PackageListUtil.GetRequiredPackagesInSourcePackageListOrder(
            requestedPackagesInOrder, resolvedBuildOrder)
def ShowRequirementList(log: Log,
                        basicConfig: BasicConfig,
                        topLevelPackage: Package,
                        requestedFiles: Optional[List[str]],
                        showFeaturesOnly: bool = False) -> None:
    message = "Requirements" if not showFeaturesOnly else "Features"
    filterName = None if not showFeaturesOnly else PackageRequirementTypeString.Feature
    # As the packages in requestedFiles might have been filtered at this point (and any issues already caught), we just ignore not found
    requestedPackages = PackageUtil.GetPackageListFromFilenames(
        topLevelPackage, requestedFiles, True)
    requirements = RequirementFilter.GetRequirementList(
        topLevelPackage, requestedPackages, filterName)

    if len(requirements) <= 0:
        log.DoPrint("{0}: None".format(message))
        return
    log.DoPrint("{0}:".format(message))

    rootNode = RequirementTree(requirements).RootNode

    strAddIndent = "  "
    # We only show the type group info when there is more than one
    #showTypeGroup = len(rootNode.Children) > 1
    baseIndent = ""  #strAddIndent if len(rootNode.Children) > 1 else ""

    sortedFeatures = list(rootNode.Children)
    sortedFeatures.sort(
        key=lambda s: None if s.Content is None else s.Content.Id)
    for sortedFeature in sortedFeatures:
        __PrintRequirementsNode(log, sortedFeature, baseIndent, strAddIndent)