Skip to content

Commit

Permalink
[issue_415] Add support for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiH committed Feb 7, 2019
1 parent eb9397c commit 19c3c2c
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 184 deletions.
6 changes: 3 additions & 3 deletions mozdownload/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from __future__ import absolute_import, unicode_literals

import re
import urllib
from HTMLParser import HTMLParser

import requests
from six.moves.html_parser import HTMLParser
from six.moves.urllib.parse import unquote


class DirectoryParser(HTMLParser):
Expand Down Expand Up @@ -68,7 +68,7 @@ def handle_starttag(self, tag, attrs):
# Links look like: /pub/firefox/nightly/2015/
# We have to trim the fragment down to the last item. Also to ensure we
# always get it, we remove a possible final slash first
url = urllib.unquote(attr[1])
url = unquote(attr[1])
self.active_url = url.rstrip('/').split('/')[-1]

return
Expand Down
23 changes: 12 additions & 11 deletions mozdownload/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
import os
import re
import sys
import urllib
from datetime import datetime
from urlparse import urlparse

import mozinfo
import progressbar as pb
import redo
import requests
from six.moves.urllib.parse import quote
from six.moves.urllib.parse import urlparse

from mozdownload import errors
from mozdownload import treeherder
from mozdownload.parser import DirectoryParser
from mozdownload.timezones import PacificTimezone
from mozdownload import treeherder
from mozdownload.utils import urljoin


APPLICATIONS = ('devedition', 'firefox', 'fennec', 'thunderbird')

# Some applications contain all locales in a single build
Expand Down Expand Up @@ -164,6 +163,7 @@ def _create_directory_parser(self, url):
@property
def binary(self):
"""Return the name of the build."""

def _get_binary():
# Retrieve all entries from the remote virtual folder
parser = self._create_directory_parser(self.path)
Expand Down Expand Up @@ -195,8 +195,8 @@ def binary_regex(self):
@property
def url(self):
"""Return the URL of the build."""
return urllib.quote(urljoin(self.path, self.binary),
safe='%/:=&?~#+!$,;\'@()*[]|')
return quote(urljoin(self.path, self.binary),
safe='%/:=&?~#+!$,;\'@()*[]|')

@property
def path(self):
Expand Down Expand Up @@ -248,6 +248,7 @@ def detect_platform(self):

def download(self):
"""Download the specified file."""

def total_seconds(td):
# Keep backward compatibility with Python 2.6 which doesn't have
# this method
Expand Down Expand Up @@ -417,7 +418,7 @@ def get_latest_build_date(self):
parser.entries = parser.filter(r'.*%s\.txt' % self.platform_regex)
if not parser.entries:
message = 'Status file for %s build cannot be found' % \
self.platform_regex
self.platform_regex
raise errors.NotFoundError(message, url)

# Read status file for the platform, retrieve build id,
Expand Down Expand Up @@ -467,7 +468,7 @@ def get_build_info_for_date(self, date, build_index=None):
# ensure to select the correct subfolder for localized builds
'L10N': '(-l10n)?' if self.locale_build else '',
'PLATFORM': '' if self.application not in (
'fennec') else '-' + self.platform
'fennec') else '-' + self.platform
}

parser.entries = parser.filter(regex)
Expand All @@ -482,7 +483,7 @@ def get_build_info_for_date(self, date, build_index=None):
if not parser.entries:
date_format = '%Y-%m-%d-%H-%M-%S' if has_time else '%Y-%m-%d'
message = 'Folder for builds on %s has not been found' % \
self.date.strftime(date_format)
self.date.strftime(date_format)
raise errors.NotFoundError(message, url)

# If no index has been given, set it to the last build of the day.
Expand Down Expand Up @@ -690,7 +691,7 @@ def get_build_info(self):
parser = self._create_directory_parser(url)
if not parser.entries:
message = 'Folder for specific candidate builds at %s has not' \
'been found' % url
'been found' % url
raise errors.NotFoundError(message, url)

self.show_matching_builds(parser.entries)
Expand Down Expand Up @@ -909,7 +910,7 @@ def get_build_info_for_index(self, build_index=None):
# If a timestamp is given, retrieve the folder with the timestamp
# as name
parser.entries = self.timestamp in parser.entries and \
[self.timestamp]
[self.timestamp]

elif self.date:
# If date is given, retrieve the subset of builds on that date
Expand Down
3 changes: 1 addition & 2 deletions mozdownload/treeherder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from mozdownload.errors import NotSupportedError


PLATFORM_MAP = {
'android-api-9': {'build_platform': 'android-2-3-armv7-api9'},
'android-api-11': {'build_platform': 'android-4-0-armv7-api11'},
Expand Down Expand Up @@ -69,7 +68,7 @@ def query_builds_by_revision(self, revision, job_type_name='Build', debug_build=

try:
self.logger.info('Querying {url} for list of builds for revision: {revision}'.format(
url=self.client.server_url, revision=revision))
url=self.client.server_url, revision=revision))

# Retrieve the option hash to filter for type of build (opt, and debug for now)
option_hash = None
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mozinfo >= 0.9
mozinfo >= 1.0.0
progressbar2 >= 3.34.3
redo==2.0.2
requests >= 2.9.1, <3.0.0
Expand Down
5 changes: 2 additions & 3 deletions tests/cli/test_correct_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import os

import mozfile
import mozhttpd_base_test as mhttpd
from mock import patch

from mozdownload import cli
import mozhttpd_base_test as mhttpd


tests = {
'release': {
Expand Down Expand Up @@ -47,7 +46,7 @@ class TestCLICorrectScraper(mhttpd.MozHttpdBaseTest):

@patch('mozdownload.treeherder.Treeherder.query_builds_by_revision')
def test_cli_scraper(self, query_builds_by_revision):
for scraper_type, data in tests.iteritems():
for scraper_type, data in tests.items():
if data.get('builds'):
query_builds_by_revision.return_value = data['builds']

Expand Down
Loading

0 comments on commit 19c3c2c

Please sign in to comment.