Exemple #1
0
    def checkIfPackageCanUpdate(self, package_id: str) -> bool:
        available_versions = self._available_package_versions.get(package_id)

        if available_versions is None:
            return False

        current_version = None

        bundled_package_dict = self._bundled_package_dict.get(package_id)
        if bundled_package_dict is not None:
            current_version = UMVersion(
                bundled_package_dict["package_info"]["package_version"])

        installed_package_dict = self._installed_package_dict.get(package_id)
        if installed_package_dict is not None:
            current_version = UMVersion(
                installed_package_dict["package_info"]["package_version"])

            # One way to check if the package has been updated in looking at the to_install information in the packages.json
            to_install_package_dict = self._to_install_package_dict.get(
                package_id)
            if to_install_package_dict is not None:  # If it's marked as to_install, that means package will be installed upon restarting
                return False

        if current_version is not None:
            for available_version in available_versions:
                if current_version < available_version:
                    # Stop looking, there is at least one version that is higher.
                    return True
        return False
Exemple #2
0
    def _shouldInstallCandidate(self, candidate_dict: Dict[str, Any],
                                base_dict: Dict[str, Any]) -> bool:
        # If the base version has a higher SDK version, use the based version by removing the candidate one.
        sdk_version_candidate = UMVersion(candidate_dict["sdk_version"])
        if not self.isPackageCompatible(sdk_version_candidate):
            return False

        # Remove the package with the old version to favour the newer based version.
        version_candidate = UMVersion(candidate_dict["package_version"])
        version_base = UMVersion(base_dict["package_version"])
        if version_candidate <= version_base:
            return False

        return True
Exemple #3
0
    def _comparePackageVersions(self, info_dict1: Dict[str, Any],
                                info_dict2: Dict[str, Any]) -> int:
        # If the bundled version has a higher SDK version, use the bundled version by removing the installed one.
        sdk_version1 = UMVersion(info_dict1["sdk_version"])
        sdk_version2 = UMVersion(info_dict2["sdk_version"])
        if sdk_version1 < sdk_version2:
            return -1

        # Remove the package with the old version to favour the newer bundled version.
        version1 = UMVersion(info_dict1["package_version"])
        version2 = UMVersion(info_dict2["package_version"])
        if version1 < version2:
            return -1

        if version1 == version2:
            return 0

        return 1
Exemple #4
0
    def canDowngrade(self, package_id: str) -> bool:
        """ Checks if the local installed package has a higher version than the bundled package

        :return: ``True`` if the package can be downgraded to a bundled version, ``False`` if the bundled version is
        higher or the same. Also returns ``False`` if there is only a bundled or an installed package present on the
        system.
        """
        local_package = self.getInstalledPackageInfo(package_id)
        if local_package is None:
            return False

        bundled_package = self.getBundledPackageInfo(package_id)
        if bundled_package is None:
            return False

        local_version = UMVersion(local_package["package_version"])
        bundled_version = UMVersion(bundled_package["package_version"])
        return bundled_version < local_version
Exemple #5
0
    def checkIfPackageCanUpdate(self, package_id: str) -> bool:
        available_versions = self._available_package_versions.get(package_id)

        if available_versions is None:
            return False

        installed_package_dict = self._installed_package_dict.get(package_id)
        if installed_package_dict is not None:
            current_version = UMVersion(
                installed_package_dict["package_info"]["package_version"])

            for available_version in available_versions:
                if current_version < available_version:
                    # Stop looking, there is at least one version that is higher.
                    return True
        return False