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

Replace packaging.LegacyVersion use with mozilla_version. Fixes #635 #638

Merged
merged 4 commits into from
Apr 17, 2023
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
28 changes: 25 additions & 3 deletions mozdownload/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
APPLICATIONS_TO_FTP_DIRECTORY = {'fennec': 'mobile'}
# Used if the application is named differently then the binary on the server
APPLICATIONS_TO_BINARY_NAME = {'devedition': 'firefox'}
# Used when sorting versions
APPLICATIONS_TO_VERSION_CLASS = {'devedition': 'DeveditionVersion',
'firefox': 'FirefoxVersion',
'fennec': 'FennecVersion',
'thunderbird': 'ThunderbirdVersion'}

# Base URL for the path to all builds
BASE_URL = 'https://archive.mozilla.org/pub/'
Expand Down Expand Up @@ -72,6 +77,22 @@
}


def thunderbird_latest_version_filter(x):
"""Ignore Thunderbird versions that mozilla-version does not accept as valid.
mozilla-version is only used to find the "latest" versions; these are old
and will not be relevant.
"""
accepted_invalid_versions = ("0.7rc", "1.0rc", "2.0.0.0", "2.0.0.0rc1", "10.0-real")
return x not in accepted_invalid_versions and \
re.match(RELEASE_AND_CANDIDATE_LATEST_VERSIONS['latest'], x)


def latest_version_filter(version, application):
if application == "thunderbird" and version == "latest":
return thunderbird_latest_version_filter
return RELEASE_AND_CANDIDATE_LATEST_VERSIONS[version]


class Scraper(object):
"""Generic class to download a Gecko based application."""

Expand Down Expand Up @@ -667,9 +688,10 @@ def query_versions(self, version=None):
url = urljoin(self.base_url, 'releases/')
parser = self._create_directory_parser(url)
if version:
versions = parser.filter(RELEASE_AND_CANDIDATE_LATEST_VERSIONS[version])
from packaging.version import LegacyVersion
versions.sort(key=LegacyVersion)
versions = parser.filter(latest_version_filter(version, self.application))
from mozilla_version import gecko
MozVersion = getattr(gecko, APPLICATIONS_TO_VERSION_CLASS[self.application])
versions.sort(key=MozVersion.parse)
return [versions[-1]]
else:
return parser.entries
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mozinfo >= 1.0.0
packaging == 21.3.0
mozilla-version >= 1.2.0
progressbar2 >= 3.34.3
redo == 2.0.4
requests >= 2.21.0, <3.0.0
Expand Down