diff --git a/mozdownload/scraper.py b/mozdownload/scraper.py index 639731d6..4ddd9920 100755 --- a/mozdownload/scraper.py +++ b/mozdownload/scraper.py @@ -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/' @@ -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.""" @@ -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 diff --git a/requirements.txt b/requirements.txt index 4fc75c61..c0995dbe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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