Skip to content

Commit

Permalink
Allow users to specify which downloader they want to use
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Mar 13, 2015
1 parent 7586cc8 commit dc7221f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
18 changes: 18 additions & 0 deletions Package Control.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@
// Additional packages to ignore when listing unmanaged packages.
"unmanaged_packages_ignore": [],

// The downloader backends that should be used for HTTP(S) requests, split
// by operating system to allow for configuration to be shared.
//
// Valid options include: "urllib", "curl", "wget", (Windows-only) "wininet"
//
// This setting allows Windows users to bypass wininet and use urllib
// instead if they machine or network presents trouble to wininet. Some
// OS X and Linux users have also reported better luck with certain proxies
// using curl or wget instead of urllib.
//
// The "curl" and "wget" options require the command line "curl" or "wget"
// program installed and present in the PATH.
"downloader_precedence": {
"windows": ["wininet"],
"osx": ["urllib"],
"linux": ["urllib", "curl", "wget"]
},

// Directories to ignore when creating a package
"dirs_to_ignore": [
".hg", ".git", ".svn", "_darcs", "CVS"
Expand Down
38 changes: 33 additions & 5 deletions package_control/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import socket
from threading import Lock, Timer
from contextlib import contextmanager
import sys

try:
# Python 3
Expand Down Expand Up @@ -210,11 +211,34 @@ def fetch(self, url, error_message, prefer_cached=False):

url = update_url(url, self.settings.get('debug'))

# We don't use sublime.platform() here since this is used for
# the crawler on packagecontrol.io also
if sys.platform == 'darwin':
platform = 'osx'
elif sys.platform == 'win32':
platform = 'windows'
else:
platform = 'linux'

downloader_precedence = self.settings.get('downloader_precedence', {})
downloader_list = downloader_precedence.get(platform, [])

if not isinstance(downloader_list, list) or len(downloader_list) == 0:
error_string = text.format(
u'''
No list of preferred downloaders specified in the
"downloader_precedence" setting for the platform "%s"
''',
platform
)
show_error(error_string)
raise DownloaderException(error_string)

# Make sure we have a downloader, and it supports SSL if we need it
if not self.downloader or (is_ssl and not self.downloader.supports_ssl()):
for downloader_class in DOWNLOADERS:
for downloader_name in downloader_list:
try:
downloader = downloader_class(self.settings)
downloader = DOWNLOADERS[downloader_name](self.settings)
if is_ssl and not downloader.supports_ssl():
continue
self.downloader = downloader
Expand All @@ -225,10 +249,14 @@ def fetch(self, url, error_message, prefer_cached=False):
if not self.downloader:
error_string = text.format(
u'''
Unable to download %s due to no ssl module available and no
capable program found.
None of the preferred downloaders can download %s.
This is usually either because the ssl module is unavailable
and/or the command line curl or wget executables could not be
found in the PATH.
Please install curl or wget.
If you customized the "downloader_precedence" setting, please
verify your customization.
''',
url
)
Expand Down
18 changes: 11 additions & 7 deletions package_control/downloaders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import os

from .urllib_downloader import UrlLibDownloader
from .curl_downloader import CurlDownloader
from .wget_downloader import WgetDownloader

DOWNLOADERS = {
'urllib': UrlLibDownloader,
'curl': CurlDownloader,
'wget': WgetDownloader
}

if os.name == 'nt':
from .wininet_downloader import WinINetDownloader
DOWNLOADERS = [WinINetDownloader]

else:
from .urllib_downloader import UrlLibDownloader
from .curl_downloader import CurlDownloader
from .wget_downloader import WgetDownloader
DOWNLOADERS = [UrlLibDownloader, CurlDownloader, WgetDownloader]
DOWNLOADERS['wininet'] = WinINetDownloader
1 change: 1 addition & 0 deletions package_control/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self):
'channels',
'debug',
'dirs_to_ignore',
'downloader_precedence',
'files_to_ignore',
'files_to_include',
'git_binary',
Expand Down

0 comments on commit dc7221f

Please sign in to comment.