Beispiel #1
0
    def get_versions(cls, project):
        """ Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        """
        url = cls.get_version_url(project)
        last_change = project.get_time_last_created_version()

        try:
            req = cls.call_url(url, last_change=last_change)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        # Not modified
        if req.status_code == 304:
            return []

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No JSON returned by %s" % url)

        if "error" in data or "versions" not in data:
            raise AnityaPluginException("No versions found at %s" % url)

        return list(data["versions"].keys())
Beispiel #2
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url = 'https://pypi.python.org/pypi/%s/json' % project.name
        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        return list(data['releases'].keys())
Beispiel #3
0
    def check_feed(cls):
        ''' Return a generator over the latest uploads to CPAN

        by querying an RSS feed.
        '''

        url = 'http://search.cpan.org/uploads.rdf'

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            parser = xml2dict.XML2Dict()
            data = parser.fromstring(response.text)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No XML returned by %s' % url)

        items = data['RDF']['item']
        for entry in items:
            title = entry['title']['value']
            name, version = title.rsplit('-', 1)
            #homepage = entry['link']['value'].rsplit('-', 1)[0] + '/'
            homepage = 'http://search.cpan.org/dist/%s/' % name
            yield name, homepage, cls.name, version
Beispiel #4
0
def get_versions_by_regex_for_text(text, url, regex, project):
    """ For the provided text, return all the version retrieved via the
    specified regular expression.

    """

    try:
        upstream_versions = list(set(re.findall(regex, text)))
    except sre_constants.error:  # pragma: no cover
        raise AnityaPluginException("%s: invalid regular expression" % project.name)

    for index, version in enumerate(upstream_versions):

        # If the version retrieved is a tuple, re-constitute it
        if type(version) == tuple:
            version = ".".join([v for v in version if not v == ""])

        upstream_versions[index] = version

        if " " in version:
            raise AnityaPluginException(
                "%s: invalid upstream version:>%s< - %s - %s "
                % (project.name, version, url, regex)
            )
    if len(upstream_versions) == 0:
        raise AnityaPluginException(
            "%(name)s: no upstream version found. - %(url)s -  "
            "%(regex)s" % {"name": project.name, "url": url, "regex": regex}
        )

    return upstream_versions
Beispiel #5
0
    def _retrieve_versions(cls, owner, repo, project):
        query = prepare_query(owner, repo, project.releases_only)

        try:
            headers = REQUEST_HEADERS.copy()
            token = config["GITHUB_ACCESS_TOKEN"]
            if token:
                headers["Authorization"] = "bearer %s" % token
            resp = http_session.post(
                API_URL,
                json={"query": query},
                headers=headers,
                timeout=60,
                verify=True,
            )
        except Exception as err:
            _log.debug("%s ERROR: %s" % (project.name, str(err)))
            raise AnityaPluginException(
                'Could not call : "%s" of "%s", with error: %s' %
                (API_URL, project.name, str(err))) from err

        if resp.ok:
            json = resp.json()
        elif resp.status_code == 403:
            _log.info("Github API ratelimit reached.")
            raise RateLimitException(reset_time)
        else:
            raise AnityaPluginException(
                '%s: Server responded with status "%s": "%s"' %
                (project.name, resp.status_code, resp.reason))

        versions = parse_json(json, project)
        _log.debug(f"Retrieved versions: {versions}")
        return versions
Beispiel #6
0
    def check_feed(cls):
        """Return a generator over the latest uploads to CPAN

        by querying an RSS feed.
        """

        url = "https://metacpan.org/feed/recent"

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            root = ET.fromstring(response.text)
        except ET.ParseError:
            raise AnityaPluginException("No XML returned by %s" % url)

        for item in root.iter(tag="{http://purl.org/rss/1.0/}item"):
            title = item.find("{http://purl.org/rss/1.0/}title")
            try:
                name, version = title.text.rsplit("-", 1)
            except ValueError:
                _log.info(
                    "Unable to parse CPAN package %s into a name and version")
            homepage = "https://metacpan.org/release/%s/" % name
            yield name, homepage, cls.name, version
Beispiel #7
0
    def get_versions(cls, project):
        """ Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        """
        url = cls.get_version_url(project)
        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No JSON returned by %s" % url)

        return list(data["releases"].keys())
Beispiel #8
0
    def check_feed(cls):
        """ Return a generator over the latest 10 uploads to PEAR

        by querying an RSS feed.
        """

        url = "https://pear.php.net/feeds/latest.rss"

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            parser = xml2dict.XML2Dict()
            data = parser.fromstring(response.text)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No XML returned by %s" % url)

        items = data["RDF"]["item"]
        for entry in items:
            title = entry["title"]["value"]
            name, version = title.rsplit(None, 1)
            homepage = "https://pear.php.net/package/%s" % name
            yield name, homepage, cls.name, version
Beispiel #9
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`model.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url = 'http://rubygems.org/api/v1/versions/%(name)s/latest.json' % {
            'name': project.name
        }

        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        if data['version'] == 'unknown':
            raise AnityaPluginException('Project or version unknown at %s' %
                                        url)

        return [data['version']]
Beispiel #10
0
    def get_version(cls, project):
        """ Method called to retrieve the latest version of the projects
        provided, project that relies on the backend of this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: the latest version found upstream
        :return type: str
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the version cannot be retrieved correctly

        """
        url = cls.get_version_url(project)
        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No JSON returned by %s" % url)

        return data["info"]["version"]
Beispiel #11
0
    def get_version(cls, project):
        ''' Method called to retrieve the latest version of the projects
        provided, project that relies on the backend of this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: the latest version found upstream
        :return type: str
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the version cannot be retrieved correctly

        '''
        url = 'https://pypi.org/pypi/%s/json' % project.name
        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        return data['info']['version']
Beispiel #12
0
    def check_feed(cls):
        ''' Return a generator over the latest 40 uploads to PyPI

        by querying an RSS feed.
        '''

        url = 'https://pypi.org/rss/updates.xml'

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            parser = xml2dict.XML2Dict()
            data = parser.fromstring(response.text)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No XML returned by %s' % url)

        items = data['rss']['channel']['item']
        for entry in items:
            title = entry['title']['value']
            name, version = title.rsplit(None, 1)
            homepage = 'https://pypi.org/project/%s/' % name
            yield name, homepage, cls.name, version
Beispiel #13
0
    def check_feed(cls):
        """ Return a generator over the latest 40 uploads to PyPI

        by querying an RSS feed.
        """

        url = "https://pypi.org/rss/updates.xml"

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            parser = xml2dict.XML2Dict()
            data = parser.fromstring(response.text)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No XML returned by %s" % url)

        items = data["rss"]["channel"]["item"]
        for entry in items:
            title = entry["title"]["value"]
            name, version = title.rsplit(None, 1)
            homepage = "https://pypi.org/project/%s/" % name
            yield name, homepage, cls.name, version
Beispiel #14
0
    def check_feed(cls):
        """Return a generator over the latest 40 uploads to npmjs.org

        by querying an weird JSON endpoint.
        """

        url = ("https://skimdb.npmjs.com/registry/_changes?"
               "feed=normal"
               "&descending=true"
               "&limit=40"
               "&include_docs=true"
               "&attachments=false")

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        try:
            data = response.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No JSON returned by %s" % url)

        for item in data["results"]:
            if item.get("deleted"):
                continue
            doc = item["doc"]
            name = doc["name"]
            homepage = doc.get("homepage",
                               "https://npmjs.org/package/%s" % name)
            for version in doc.get("versions", []):
                yield name, homepage, cls.name, version
Beispiel #15
0
def get_versions_by_regex_for_text(text, url, regex, project):
    ''' For the provided text, return all the version retrieved via the
    specified regular expression.

    '''

    try:
        upstream_versions = list(set(re.findall(regex, text)))
    except sre_constants.error:  # pragma: no cover
        raise AnityaPluginException(
            "%s: invalid regular expression" % project.name)

    for index, version in enumerate(upstream_versions):

        # If the version retrieved is a tuple, re-constitute it
        if type(version) == tuple:
            version = ".".join([v for v in version if not v == ""])

        # Strip the version_prefix early
        if project.version_prefix is not None and \
                version.startswith(project.version_prefix):
            version = version[len(project.version_prefix):]
        upstream_versions[index] = version

        if " " in version:
            raise AnityaPluginException(
                "%s: invalid upstream version:>%s< - %s - %s " % (
                    project.name, version, url, regex))
    if len(upstream_versions) == 0:
        raise AnityaPluginException(
            "%(name)s: no upstream version found. - %(url)s -  "
            "%(regex)s" % {
                'name': project.name, 'url': url, 'regex': regex})

    return upstream_versions
Beispiel #16
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`model.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url = 'https://pagure.io/api/0/%s/git/tags' % project.name
        try:
            req = cls.call_url(url)
        except Exception as err:  # pragma: no cover
            print err
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        return data.get('tags', [])
Beispiel #17
0
    def get_version(cls, project):
        """Method called to retrieve the latest version of the projects
        provided, project that relies on the backend of this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: the latest version found upstream
        :return type: str
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the version cannot be retrieved correctly

        """
        url = cls.get_version_url(project)
        last_change = project.get_time_last_created_version()

        try:
            req = cls.call_url(url, last_change=last_change)
        except Exception:  # pragma: no cover
            raise AnityaPluginException("Could not contact %s" % url)

        # Not modified
        if req.status_code == 304:
            return None

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException("No JSON returned by %s" % url)

        if "dist-tags" in data and "latest" in data["dist-tags"]:
            return data["dist-tags"]["latest"]
        else:
            return cls.get_ordered_versions(project)[-1]
Beispiel #18
0
    def check_feed(cls):
        ''' Return a generator over the latest 40 uploads to npmjs.org

        by querying an weird JSON endpoint.
        '''

        url = ('https://skimdb.npmjs.com/registry/_changes?'
               'feed=normal'
               '&descending=true'
               '&limit=40'
               '&include_docs=true'
               '&attachments=false')

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = response.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        for item in data['results']:
            if item.get('deleted'):
                continue
            doc = item['doc']
            name = doc['name']
            homepage = doc.get('homepage',
                               'https://npmjs.org/package/%s' % name)
            for version in doc.get('versions', []):
                yield name, homepage, cls.name, version
Beispiel #19
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url_template = 'https://registry.npmjs.org/%(name)s'

        url = url_template % {'name': project.name}

        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        if 'error' in data or 'versions' not in data:
            raise AnityaPluginException('No versions found at %s' % url)

        return list(data['versions'].keys())
Beispiel #20
0
    def get_version(cls, project):
        ''' Method called to retrieve the latest version of the projects
        provided, project that relies on the backend of this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: the latest version found upstream
        :return type: str
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the version cannot be retrieved correctly

        '''
        url_template = 'https://registry.npmjs.org/%(name)s'

        url = url_template % {'name': project.name}

        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            data = req.json()
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No JSON returned by %s' % url)

        if 'dist-tags' in data and 'latest' in data['dist-tags']:
            return data['dist-tags']['latest']
        else:
            return cls.get_ordered_versions(project)[-1]
Beispiel #21
0
    def check_feed(cls):
        ''' Return a generator over the latest 10 uploads to PEAR

        by querying an RSS feed.
        '''

        url = 'https://pear.php.net/feeds/latest.rss'

        try:
            response = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not contact %s' % url)

        try:
            parser = xml2dict.XML2Dict()
            data = parser.fromstring(response.text)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('No XML returned by %s' % url)

        items = data['RDF']['item']
        for entry in items:
            title = entry['title']['value']
            name, version = title.rsplit(None, 1)
            homepage = 'http://pear.php.net/package/%s' % name
            yield name, homepage, cls.name, version
Beispiel #22
0
    def get_versions(cls, project):
        """Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        Args:
            project (:obj:`anitya.db.models.Project`): Project object whose backend
                corresponds to the current plugin.

        Returns:
            :obj:`list`: A list of all the possible releases found

        Raises:
            AnityaPluginException: A
                :obj:`anitya.lib.exceptions.AnityaPluginException` exception
                when the versions cannot be retrieved correctly

        """
        owner = None
        repo = None
        url = cls.get_version_url(project)
        if url:
            url = url.replace("https://github.com/", "")
            url = url.replace("/tags", "")
        else:
            raise AnityaPluginException("Project %s was incorrectly set up." %
                                        project.name)

        try:
            (owner, repo) = url.split("/")
        except ValueError:
            raise AnityaPluginException("""Project {} was incorrectly set up.
                Can\'t parse owner and repo.""".format(project.name))

        # If we know about the cursor of the latest version, attempt to
        # limit results to anything after it.
        versions = cls._retrieve_versions(owner,
                                          repo,
                                          project,
                                          cursor=project.latest_version_cursor)

        if versions is None:
            # Either a previous version cursor wasn't known, or turned out to
            # be invalid. Unset it for the latter case.
            project.latest_version_cursor = None
            versions = cls._retrieve_versions(owner, repo, project)

        if len(versions) == 0 and project.latest_version_cursor is None:
            raise AnityaPluginException("%s: No upstream version found." %
                                        (project.name))

        # Filter retrieved versions
        filtered_versions = cls.filter_versions(versions,
                                                project.version_filter)
        return filtered_versions
Beispiel #23
0
    def get_versions(cls, project):
        """Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        Args:
            project (:obj:`anitya.db.models.Project`): Project object whose backend
                corresponds to the current plugin.

        Returns:
            :obj:`list`: A list of all the possible releases found

        Raises:
            AnityaPluginException: A
                :obj:`anitya.lib.exceptions.AnityaPluginException` exception
                when the versions cannot be retrieved correctly

        """
        owner = None
        repo = None
        url = cls.get_version_url(project)
        if url:
            url = url.replace("https://github.com/", "")
            url = url.replace("/tags", "")
        else:
            raise AnityaPluginException(
                "Project %s was incorrectly set up." % project.name
            )

        try:
            (owner, repo) = url.split("/")
        except ValueError:
            raise AnityaPluginException(
                """Project {} was incorrectly set up.
                Can\'t parse owner and repo.""".format(
                    project.name
                )
            )

        versions = cls._retrieve_versions(owner, repo, project)

        if len(versions) == 0:
            raise AnityaPluginException(
                "%s: No upstream version found." % (project.name)
            )

        # Filter retrieved versions
        filtered_versions = cls.filter_versions(versions, project.version_filter)
        return filtered_versions
Beispiel #24
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url_template = '%(hostname)s/api/v4/projects/%(owner)s%%2F%(repo)s/repository/tags'
        if project.version_url:
            tokens = project.version_url.split('/')
        elif project.homepage:
            tokens = project.homepage.split('/')
        else:
            raise AnityaPluginException(
                'Project %s was incorrectly set-up' % project.name)

        url = url_template % {'hostname': tokens[0] + '//' + tokens[2],
                              'owner': tokens[3],
                              'repo': tokens[4]}

        resp = cls.call_url(url)

        if resp.ok:
            json = resp.json()
        else:
            raise AnityaPluginException(
                '%s: Server responded with status "%s": "%s"' % (
                    project.name, resp.status_code, resp.reason))

        _log.debug('Received %d tags for %s' % (len(json), project.name))

        tags = []
        for tag in json:
            tags.append(tag["name"])

        if len(tags) == 0:
            raise AnityaPluginException(
                '%s: No upstream version found.' % (
                    project.name))

        return tags
Beispiel #25
0
    def _get_versions(cls, project):
        """
        Make a request for all versions of the project provided.

        Args:
            project (anitya.lib.anitya.db.models.Project): The Rust project to retrieve
                versions for.

        Returns:
            list: A list of version dictionaries. Each dictionary is in the format::
                {
                    "crate": "itoa",
                    "created_at": "2017-01-26T05:02:29Z",
                    "dl_path": "/api/v1/crates/itoa/0.2.1/download",
                    "downloads": 150,
                    "features": {},
                    "id": 43354,
                    "links": {
                        "authors": "/api/v1/crates/itoa/0.2.1/authors",
                        "dependencies": "/api/v1/crates/itoa/0.2.1/dependencies",
                        "version_downloads": "/api/v1/crates/itoa/0.2.1/downloads"
                    },
                    "num": "0.2.1",
                    "updated_at": "2017-01-26T05:02:29Z",
                    "yanked": false
                }

        Raises:
            AnityaPluginException: If the URL was unreachable or the response
                was in an unexpected format.
        """
        url = cls.get_version_url(project)
        last_change = project.get_time_last_created_version()
        try:
            req = cls.call_url(url, last_change=last_change)
            req.raise_for_status()
            # Not modified
            if req.status_code == 304:
                return []
            data = req.json()
        except requests.RequestException as e:
            raise AnityaPluginException("Could not contact {url}: "
                                        "{reason!r}".format(url=url, reason=e))
        except ValueError as e:
            raise AnityaPluginException(
                "Failed to decode JSON: {!r}".format(e))

        return data["versions"]
Beispiel #26
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        if project.version_url:
            url_template = 'https://github.com/%(version_url)s/tags'
            version_url = project.version_url.replace('https://github.com/',
                                                      '')
            url = url_template % {'version_url': version_url}
        elif project.homepage.startswith('https://github.com'):
            url = project.homepage
            if url.endswith('/'):
                url = project.homepage[:-1]
            url += '/tags'
        else:
            raise AnityaPluginException('Project %s was incorrectly set-up' %
                                        project.name)

        return get_versions_by_regex(url, REGEX, project)
Beispiel #27
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`model.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url_template = 'https://pear.php.net/rest/r/%(name)s/allreleases.xml'

        url = url_template % {'name': project.name.lower()}
        versions = []
        try:
            versions = _get_versions(url)
        except AnityaPluginException:
            pass

        if not versions and '-' in project.name:
            pname = project.name.lower().replace('-', '_')
            url = url_template % {'name': pname}
            versions = _get_versions(url)

        if not versions:
            raise AnityaPluginException('No versions found for %s' %
                                        project.name.lower())

        return versions
Beispiel #28
0
    def get_versions(cls, project):
        """Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        """
        url = cls.get_version_url(project)
        versions = []
        versions = _get_versions(url)

        if not versions:
            raise AnityaPluginException("No versions found for %s" %
                                        project.name.lower())

        # Filter retrieved versions
        filtered_versions = cls.filter_versions(versions,
                                                project.version_filter)

        return filtered_versions
Beispiel #29
0
    def get_versions(cls, project):
        ''' Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`model.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        '''
        url = project.version_url

        try:
            req = cls.call_url(url)
        except Exception:
            raise AnityaPluginException(
                'Could not call : "%s" of "%s"' % (url, project.name))

        versions = None
        if not isinstance(req, six.string_types):
            req = req.text

        try:
            regex = REGEX % {'name': project.name.replace('+', '\+')}
            versions = get_versions_by_regex_for_text(
                req, url, regex, project)
        except AnityaPluginException:
            versions = get_versions_by_regex_for_text(
                req, url, DEFAULT_REGEX, project)

        return versions
Beispiel #30
0
    def get_versions(cls, project):
        """ Method called to retrieve all the versions (that can be found)
        of the projects provided, project that relies on the backend of
        this plugin.

        :arg Project project: a :class:`anitya.db.models.Project` object whose backend
            corresponds to the current plugin.
        :return: a list of all the possible releases found
        :return type: list
        :raise AnityaPluginException: a
            :class:`anitya.lib.exceptions.AnityaPluginException` exception
            when the versions cannot be retrieved correctly

        """
        url = cls.get_version_url(project)

        try:
            req = cls.call_url(url)
        except Exception:  # pragma: no cover
            raise AnityaPluginException('Could not call : "%s" of "%s"' %
                                        (url, project.name))

        versions = None
        try:
            regex = REGEX % {"name": project.name}
            versions = get_versions_by_regex_for_text(req.text, url, regex,
                                                      project)
        except AnityaPluginException:
            versions = get_versions_by_regex_for_text(req.text, url,
                                                      DEFAULT_REGEX, project)

        return versions