Beispiel #1
0
    def process_blacklist(entries):
        result = []

        if not isinstance(entries, list):
            return result

        for entry in entries:
            if "plugin" not in entry:
                continue

            if "octoversions" in entry and not is_octoprint_compatible(
                    *entry["octoversions"]):
                continue

            if "pythonversions" in entry and not is_python_compatible(
                    *entry["pythonversions"]):
                continue

            if "pluginversions" in entry:
                logger.debug("Blacklisted plugin: {}, versions: {}".format(
                    entry["plugin"], ", ".join(entry["pluginversions"])))
                for version in entry["pluginversions"]:
                    result.append((entry["plugin"], version))
            elif "versions" in entry:
                logger.debug("Blacklisted plugin: {}, versions: {}".format(
                    entry["plugin"], ", ".join(entry["versions"])))
                for version in entry["versions"]:
                    result.append((entry["plugin"], "=={}".format(version)))
            else:
                logger.debug("Blacklisted plugin: {}".format(entry["plugin"]))
                result.append(entry["plugin"])

        return result
Beispiel #2
0
def _filter_out_latest(releases,
                       include_prerelease=False,
                       python_version=None):
    """
    Filters out the newest of all matching releases.

    Tests:

        >>> requires_py2 = ">=2.7.9,<3"
        >>> requires_py23 = ">=2.7.9, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4"
        >>> requires_py3 = ">=3.6, <4"
        >>> releases = {"1.3.12": [dict(requires_python=requires_py2, upload_time_iso_8601="2019-10-22T10:06:03.190293Z")], "1.4.0rc1": [dict(requires_python=requires_py23, upload_time_iso_8601="2019-11-22T10:06:03.190293Z")], "2.0.0rc1": [dict(requires_python=requires_py3, upload_time_iso_8601="2020-10-22T10:06:03.190293Z")]}
        >>> to_native_str(_filter_out_latest(releases, python_version="2.7.9"))
        '1.3.12'
        >>> to_native_str(_filter_out_latest(releases, include_prerelease=True, python_version="2.7.9"))
        '1.4.0rc1'
        >>> to_native_str(_filter_out_latest(releases, include_prerelease=True, python_version="3.6.0"))
        '2.0.0rc1'
        >>> to_native_str(_filter_out_latest(releases, python_version="3.6.0"))
    """
    releases = [{"version": k, "data": v[0]} for k, v in releases.items()]

    # filter out prereleases and versions incompatible to our python
    filter_function = lambda release: not is_prerelease(release[
        "version"]) and is_python_compatible(release["data"].get(
            "requires_python", ""),
                                             python_version=python_version)
    if include_prerelease:
        filter_function = lambda release: is_python_compatible(
            release["data"].get("requires_python", ""),
            python_version=python_version)

    releases = list(filter(filter_function, releases))
    if not releases:
        return None

    # sort by upload date
    releases = sorted(
        releases,
        key=lambda release: release["data"].get("upload_time_iso_8601", ""))

    # latest release = last in list
    latest = releases[-1]

    return latest["version"]
Beispiel #3
0
 def on_api_get(self, request):
     webresponse = requests.get(
         "https://plugins.octoprint.org/plugins.json")
     plugins = webresponse.json()
     if request.args.get("python_version"):
         check_against = request.args.get("python_version")
         for entry in plugins:
             to_check = entry.get("compatibility",
                                  dict()).get("python", ">=2.7,<3")
             entry["python_compat"] = version.is_python_compatible(
                 to_check, python_version=check_against)
     return flask.jsonify(plugins)
Beispiel #4
0
def _get_latest_release(package, include_prerelease):
    from ..exceptions import NetworkError

    try:
        r = requests.get(INFO_URL.format(package=package), timeout=(3.05, 30))
    except requests.ConnectionError as exc:
        raise NetworkError(cause=exc)

    if not r.status_code == requests.codes.ok:
        return None

    data = r.json()
    if "info" not in data or "version" not in data["info"]:
        return None

    requires_python = data["info"].get("requires_python")
    if requires_python and not is_python_compatible(requires_python):
        return None

    return _filter_out_latest(data["releases"], include_prerelease=include_prerelease)