mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 15:20:16 +00:00
use curl instead of urllib
This commit is contained in:
@@ -104,7 +104,7 @@ Options
|
||||
=======
|
||||
|
||||
\-f | --force
|
||||
Force installation of a Python.
|
||||
Force installation of a Python. (skip `make test`)
|
||||
|
||||
\-C | --configure
|
||||
Custom configure options.
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ Options
|
||||
=======
|
||||
|
||||
\-f | --force
|
||||
Force installation of a Python.
|
||||
Force installation of a Python. (skip `make test`)
|
||||
|
||||
\-C | --configure
|
||||
Custom configure options.
|
||||
|
||||
@@ -5,7 +5,7 @@ from pythonbrew.define import PATH_DISTS, VERSION, ROOT,\
|
||||
PATH_BUILD
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader, get_pythonbrew_update_url,\
|
||||
get_response_from_url, get_stable_version
|
||||
get_stable_version, get_headerinfo_from_url
|
||||
from pythonbrew.util import rm_r, unpack_downloadfile, Link, is_gzip, Subprocess
|
||||
|
||||
class UpdateCommand(Command):
|
||||
@@ -28,8 +28,8 @@ class UpdateCommand(Command):
|
||||
if not download_url:
|
||||
logger.error("`%s` of pythonbrew not found." % version)
|
||||
sys.exit(1)
|
||||
resp = get_response_from_url(download_url)
|
||||
content_type = resp.info()['content-type']
|
||||
headinfo = get_headerinfo_from_url(download_url)
|
||||
content_type = headinfo['content-type']
|
||||
if not is_gzip(content_type, Link(download_url).filename):
|
||||
logger.error("Invalid content-type: `%s`" % content_type)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,51 +1,21 @@
|
||||
import sys
|
||||
import urllib
|
||||
import urllib2
|
||||
from pythonbrew.util import size_format
|
||||
from pythonbrew.define import PYTHON_VERSION_URL, PYTHONBREW_STABLE_VERSION_URL, \
|
||||
PYTHONBREW_UPDATE_URL_PYPI, PYTHONBREW_UPDATE_URL_HEAD
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.curl import Curl
|
||||
|
||||
def get_response_from_url(url):
|
||||
try:
|
||||
resp = urllib2.urlopen(url)
|
||||
except urllib2.HTTPError, e:
|
||||
logger.error("HTTP error %s while getting %s" % (e.code, url))
|
||||
sys.exit(1)
|
||||
except IOError, e:
|
||||
# Typically an FTP error
|
||||
logger.error("Error %s while getting %s" % (e, url))
|
||||
sys.exit(1)
|
||||
return resp
|
||||
def get_headerinfo_from_url(url):
|
||||
c = Curl()
|
||||
return c.readheader(url)
|
||||
|
||||
def get_stable_version():
|
||||
resp = get_response_from_url(PYTHONBREW_STABLE_VERSION_URL)
|
||||
return resp.read()
|
||||
c = Curl()
|
||||
return c.read(PYTHONBREW_STABLE_VERSION_URL)
|
||||
|
||||
class Downloader(object):
|
||||
def __init__(self):
|
||||
self._msg = ""
|
||||
self._last_msg = ""
|
||||
self._bytes = 0.0
|
||||
|
||||
def download(self, msg, url, path):
|
||||
self._msg = msg
|
||||
self._bytes = 0
|
||||
urllib.urlretrieve(url, path, self._download_progress)
|
||||
print " downloaded."
|
||||
|
||||
def _download_progress(self, block, blockbytes, maxbytes):
|
||||
self._bytes += float(blockbytes)
|
||||
if self._bytes >= maxbytes:
|
||||
self._bytes = maxbytes
|
||||
percent = (self._bytes / maxbytes) * 100
|
||||
max_size = size_format(maxbytes)
|
||||
now_size = size_format(self._bytes)
|
||||
now_msg = "\rDownloading %s (%s): %3i%% %s" % (self._msg, max_size, percent, now_size)
|
||||
padding = " " * (len(self._last_msg) - len(now_msg))
|
||||
sys.stdout.write("%s%s" % (now_msg, padding))
|
||||
sys.stdout.flush()
|
||||
self._last_msg = now_msg
|
||||
logger.info("Downloading %s as %s" % (msg, path))
|
||||
c = Curl()
|
||||
c.fetch(url, path)
|
||||
|
||||
def get_pythonbrew_update_url(version):
|
||||
if version == "head":
|
||||
|
||||
@@ -13,7 +13,7 @@ from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
|
||||
PATH_BIN_PYBREW, ROOT, PATH_LOG, DISTRIBUTE_SETUP_DLSITE, PATH_PATCHES,\
|
||||
PATH_PATCHES_MACOSX_PYTHON25, PATH_PATCHES_MACOSX_PYTHON24
|
||||
from pythonbrew.downloader import get_python_version_url, Downloader,\
|
||||
get_response_from_url
|
||||
get_headerinfo_from_url
|
||||
from pythonbrew.log import logger
|
||||
|
||||
def install_pythonbrew():
|
||||
@@ -115,8 +115,8 @@ class PythonInstaller(object):
|
||||
self.install_dir = "%s/%s" % (PATH_PYTHONS, pkg.name)
|
||||
self.build_dir = "%s/%s" % (PATH_BUILD, pkg.name)
|
||||
self.download_file = "%s/%s" % (PATH_DISTS, filename)
|
||||
resp = get_response_from_url(self.download_url)
|
||||
self.content_type = resp.info()['content-type']
|
||||
headerinfo = get_headerinfo_from_url(self.download_url)
|
||||
self.content_type = headerinfo['content-type']
|
||||
self.options = options
|
||||
self.logfile = "%s/build.log" % PATH_LOG
|
||||
|
||||
|
||||
Reference in New Issue
Block a user