Skip to content

Commit dc7221f

Browse files
committed
Allow users to specify which downloader they want to use
1 parent 7586cc8 commit dc7221f

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

Package Control.sublime-settings

+18
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@
123123
// Additional packages to ignore when listing unmanaged packages.
124124
"unmanaged_packages_ignore": [],
125125

126+
// The downloader backends that should be used for HTTP(S) requests, split
127+
// by operating system to allow for configuration to be shared.
128+
//
129+
// Valid options include: "urllib", "curl", "wget", (Windows-only) "wininet"
130+
//
131+
// This setting allows Windows users to bypass wininet and use urllib
132+
// instead if they machine or network presents trouble to wininet. Some
133+
// OS X and Linux users have also reported better luck with certain proxies
134+
// using curl or wget instead of urllib.
135+
//
136+
// The "curl" and "wget" options require the command line "curl" or "wget"
137+
// program installed and present in the PATH.
138+
"downloader_precedence": {
139+
"windows": ["wininet"],
140+
"osx": ["urllib"],
141+
"linux": ["urllib", "curl", "wget"]
142+
},
143+
126144
// Directories to ignore when creating a package
127145
"dirs_to_ignore": [
128146
".hg", ".git", ".svn", "_darcs", "CVS"

package_control/download_manager.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import socket
33
from threading import Lock, Timer
44
from contextlib import contextmanager
5+
import sys
56

67
try:
78
# Python 3
@@ -210,11 +211,34 @@ def fetch(self, url, error_message, prefer_cached=False):
210211

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

214+
# We don't use sublime.platform() here since this is used for
215+
# the crawler on packagecontrol.io also
216+
if sys.platform == 'darwin':
217+
platform = 'osx'
218+
elif sys.platform == 'win32':
219+
platform = 'windows'
220+
else:
221+
platform = 'linux'
222+
223+
downloader_precedence = self.settings.get('downloader_precedence', {})
224+
downloader_list = downloader_precedence.get(platform, [])
225+
226+
if not isinstance(downloader_list, list) or len(downloader_list) == 0:
227+
error_string = text.format(
228+
u'''
229+
No list of preferred downloaders specified in the
230+
"downloader_precedence" setting for the platform "%s"
231+
''',
232+
platform
233+
)
234+
show_error(error_string)
235+
raise DownloaderException(error_string)
236+
213237
# Make sure we have a downloader, and it supports SSL if we need it
214238
if not self.downloader or (is_ssl and not self.downloader.supports_ssl()):
215-
for downloader_class in DOWNLOADERS:
239+
for downloader_name in downloader_list:
216240
try:
217-
downloader = downloader_class(self.settings)
241+
downloader = DOWNLOADERS[downloader_name](self.settings)
218242
if is_ssl and not downloader.supports_ssl():
219243
continue
220244
self.downloader = downloader
@@ -225,10 +249,14 @@ def fetch(self, url, error_message, prefer_cached=False):
225249
if not self.downloader:
226250
error_string = text.format(
227251
u'''
228-
Unable to download %s due to no ssl module available and no
229-
capable program found.
252+
None of the preferred downloaders can download %s.
253+
254+
This is usually either because the ssl module is unavailable
255+
and/or the command line curl or wget executables could not be
256+
found in the PATH.
230257
231-
Please install curl or wget.
258+
If you customized the "downloader_precedence" setting, please
259+
verify your customization.
232260
''',
233261
url
234262
)
+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import os
22

3+
from .urllib_downloader import UrlLibDownloader
4+
from .curl_downloader import CurlDownloader
5+
from .wget_downloader import WgetDownloader
6+
7+
DOWNLOADERS = {
8+
'urllib': UrlLibDownloader,
9+
'curl': CurlDownloader,
10+
'wget': WgetDownloader
11+
}
12+
313
if os.name == 'nt':
414
from .wininet_downloader import WinINetDownloader
5-
DOWNLOADERS = [WinINetDownloader]
6-
7-
else:
8-
from .urllib_downloader import UrlLibDownloader
9-
from .curl_downloader import CurlDownloader
10-
from .wget_downloader import WgetDownloader
11-
DOWNLOADERS = [UrlLibDownloader, CurlDownloader, WgetDownloader]
15+
DOWNLOADERS['wininet'] = WinINetDownloader

package_control/package_manager.py

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(self):
7171
'channels',
7272
'debug',
7373
'dirs_to_ignore',
74+
'downloader_precedence',
7475
'files_to_ignore',
7576
'files_to_include',
7677
'git_binary',

0 commit comments

Comments
 (0)