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

Installation of Chromedriver via HTTP proxy #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 28 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@
r'Latest-Release:-ChromeDriver-(\d+\.\d+)'
)

SOCKET_PATTERN = re.compile(r'[0-9]+(?:\.[0-9]+){3}:[0-9]+')

# Global variables
chromedriver_version = None
chromedriver_checksums = None
http_proxy = None


def get_chromedriver_version():
"""Retrieves the most recent chromedriver version."""
global chromedriver_version
global chromedriver_version, http_proxy


response = request.urlopen(CHROMEDRIVER_INFO_URL)
if http_proxy:
response = urllib.urlopen(CHROMEDRIVER_INFO_URL, proxies=http_proxy)
else:
response = request.urlopen(CHROMEDRIVER_INFO_URL)
content = response.read()
match = CROMEDRIVER_LATEST_VERSION_PATTERN.search(str(content))
if match:
Expand Down Expand Up @@ -84,7 +91,12 @@ def reporthoook(x, y, z):
sys.stdout.write(' OK')
sys.stdout.flush()

request.urlretrieve(url, zip_path, reporthoook)
if http_proxy:
opener = urllib.URLopener(proxies=http_proxy)
else:
opener = urllib.URLopener()

opener.retrieve(url, zip_path, reporthoook)

print('')
if not download_ok:
Expand All @@ -107,7 +119,7 @@ def _validate(self, zip_path):
return checksum in chromedriver_checksums

def run(self):
global chromedriver_version, chromedriver_checksums
global chromedriver_version, chromedriver_checksums, http_proxy

validate = False

Expand Down Expand Up @@ -162,15 +174,17 @@ class Install(install):
user_options = install.user_options + [
('chromedriver-version=', None, 'Chromedriver version'),
('chromedriver-checksums=', None, 'Chromedriver checksums'),
('proxy-settings=', None, 'HTTP proxy for downloading ChromeDriver'),
]

def initialize_options(self):
self.chromedriver_version = None
self.chromedriver_checksums = []
self.proxy_settings = None
install.initialize_options(self)

def run(self):
global chromedriver_version, chromedriver_checksums
global chromedriver_version, chromedriver_checksums, http_proxy

if self.chromedriver_version:
if not CHROMEDRIVER_VERSION_PATTERN.match(self.chromedriver_version):
Expand All @@ -185,8 +199,16 @@ def run(self):
chromedriver_checksums = [ch.strip() for ch in
self.chromedriver_checksums.split(',')]

install.run(self)
if self.proxy_settings != None:
if not SOCKET_PATTERN.match(self.proxy_settings):
raise Exception('Invalid --proxy_settings={0}! '
'Must match /{1}/'
.format(self.proxy_settings,
SOCKET_PATTERN.pattern))
else:
http_proxy = {'http': 'http://'+self.proxy_settings}

install.run(self)

setup(
name='chromedriver_installer',
Expand Down