Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show version url on project page #663

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions anitya/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ def create_version_objects(self, versions):

return versions

def get_version_url(self):
''' Returns full version url, which is used by backend.

Returns:
str: Version url or empty string if backend is not specified
'''
if not self.backend:
return ""

backend = BACKEND_PLUGINS.get_plugin(self.backend)
return backend.get_version_url(self)

def get_sorted_version_objects(self):
''' Return list of all version objects stored, sorted from newest to oldest.

Expand Down
14 changes: 14 additions & 0 deletions anitya/lib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ def get_version(self, project): # pragma: no cover
'''
pass

@classmethod
def get_version_url(cls, project): # pragma: no cover
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
pass

@classmethod
def get_versions(self, project): # pragma: no cover
''' Method called to retrieve all the versions (that can be found)
Expand Down
44 changes: 32 additions & 12 deletions anitya/lib/backends/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url_template = 'https://bitbucket.org/%(version_url)s/' \
'downloads?tab=tags'
url = ''
if project.version_url:
url = project.version_url.replace(
'https://bitbucket.org/', '')
elif project.homepage.startswith('https://bitbucket.org'):
url = project.homepage.replace(
'https://bitbucket.org/', '')

if url.endswith('/'):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use url.strip("/") here instead of the if logic

url = url[:-1]

if url:
url = url_template % {'version_url': url}

return url

@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -59,18 +89,8 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
if project.version_url:
url_template = 'https://bitbucket.org/%(version_url)s/'\
'downloads?tab=tags'
version_url = project.version_url.replace(
'https://bitbucket.org/', '')
url = url_template % {'version_url': version_url}
elif project.homepage.startswith('https://bitbucket.org'):
url = project.homepage
if url.endswith('/'):
url = project.homepage[:1]
url += '/downloads?tab=tags'
else:
url = cls.get_version_url(project)
if not url:
raise AnityaPluginException(
'Project %s was incorrectly set-up' % project.name)

Expand Down
20 changes: 18 additions & 2 deletions anitya/lib/backends/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url = 'https://metacpan.org/release/%(name)s/' % {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to have some consistency in the use of the % format operator and format() method. Also if anitya is Python 3 only and runs on Python 3.6 f-strings are nice.

'name': project.name}

return url

@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -63,8 +80,7 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
url = 'https://metacpan.org/release/%(name)s/' % {
'name': project.name}
url = cls.get_version_url(project)

regex = REGEX % {'name': project.name}

Expand Down
18 changes: 17 additions & 1 deletion anitya/lib/backends/cran.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def get_version(cls, project):

return data['Version']

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url = 'https://crandb.r-pkg.org/{name}/all'.format(name=project.name)

return url

@classmethod
def get_versions(cls, project):
"""
Expand All @@ -108,7 +124,7 @@ def get_versions(cls, project):
format.

"""
url = 'https://crandb.r-pkg.org/{name}/all'.format(name=project.name)
url = cls.get_version_url(project)

try:
response = cls.call_url(url)
Expand Down
18 changes: 17 additions & 1 deletion anitya/lib/backends/crates.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _get_versions(cls, project):
AnityaPluginException: If the URL was unreachable or the response
was in an unexpected format.
"""
url = 'https://crates.io/api/v1/crates/{}/versions'.format(project.name)
url = cls.get_version_url(project)
try:
req = cls.call_url(url)
req.raise_for_status()
Expand Down Expand Up @@ -178,6 +178,22 @@ def get_version(cls, project):
"""
return cls._get_versions(project)[0]['num']

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url = 'https://crates.io/api/v1/crates/{}/versions'.format(project.name)

return url

@classmethod
def get_versions(cls, project):
"""
Expand Down
18 changes: 17 additions & 1 deletion anitya/lib/backends/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url = project.version_url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
url = project.version_url


return url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return url
return project.version_url


@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -64,7 +80,7 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
url = project.version_url
url = cls.get_version_url(project)

regex = REGEX_ALIASES['DEFAULT']
if project.regex:
Expand Down
34 changes: 25 additions & 9 deletions anitya/lib/backends/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
url_template = 'http://ftp.debian.org/debian/pool/main/' \
'%(short)s/%(name)s/'

if project.name.startswith('lib'):
short = project.name[:4]
else:
short = project.name[0]

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

return url

@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -64,15 +88,7 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
url_template = 'http://ftp.debian.org/debian/pool/main/'\
'%(short)s/%(name)s/'

if project.name.startswith('lib'):
short = project.name[:4]
else:
short = project.name[0]

url = url_template % {'short': short, 'name': project.name}
url = cls.get_version_url(project)
regex = DEBIAN_REGEX % {'name': project.name}

return get_versions_by_regex(url, regex, project)
42 changes: 29 additions & 13 deletions anitya/lib/backends/drupal6.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
name = project.name
if name.lower().strip().startswith('drupal6:'):
name = name[len('drupal6:'):].strip()
if '-' in project.name:
name = project.name.replace("-", "_")

url_template = 'https://updates.drupal.org/release-history/' \
'%(name)s/6.x'

url = url_template % {'name': name}

return url

@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -62,25 +87,16 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
url = cls.get_version_url(project)
name = project.name
if name.lower().strip().startswith('drupal6:'):
name = name[len('drupal6:'):].strip()

url_template = 'https://updates.drupal.org/release-history/'\
'%(name)s/6.x'

url = url_template % {'name': name}
if '-' in project.name:
name = project.name.replace("-", "_")
regex = REGEX % {'name': name}
versions = None

try:
versions = get_versions_by_regex(url, regex, project)
except AnityaPluginException as err:
if '-' not in project.name:
raise err
name = project.name.replace("-", "_")
url = url_template % {'name': name}
regex = REGEX % {'name': name}
versions = get_versions_by_regex(url, regex, project)
raise err

return versions
40 changes: 28 additions & 12 deletions anitya/lib/backends/drupal7.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ def get_version(cls, project):
'''
return cls.get_ordered_versions(project)[-1]

@classmethod
def get_version_url(cls, project):
''' Method called to retrieve the url used to check for new version
of the project provided, project that relies on the backend of this plugin.

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

Returns:
str: url used for version checking
'''
name = project.name
if name.lower().strip().startswith('drupal7:'):
name = name[len('drupal7:'):].strip()
if '-' in project.name:
name = project.name.replace("-", "_")

url_template = 'https://updates.drupal.org/release-history/' \
'%(name)s/7.x'

url = url_template % {'name': name}

return url

@classmethod
def get_versions(cls, project):
''' Method called to retrieve all the versions (that can be found)
Expand All @@ -62,25 +87,16 @@ def get_versions(cls, project):
when the versions cannot be retrieved correctly

'''
url = cls.get_version_url(project)
name = project.name
if name.lower().strip().startswith('drupal7:'):
name = name[len('drupal7:'):].strip()

url_template = 'https://updates.drupal.org/release-history/'\
'%(name)s/7.x'

url = url_template % {'name': name}
if '-' in project.name:
name = project.name.replace("-", "_")
regex = REGEX % {'name': name}
versions = None

try:
versions = get_versions_by_regex(url, regex, project)
except AnityaPluginException as err:
if '-' not in project.name:
raise err
name = project.name.replace("-", "_")
url = url_template % {'name': name}
regex = REGEX % {'name': name}
versions = get_versions_by_regex(url, regex, project)

return versions
Loading