mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 15:20:16 +00:00
support python3
This commit is contained in:
+3
-2
@@ -3,6 +3,7 @@ import re
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.util import u
|
||||
|
||||
class Curl(object):
|
||||
def __init__(self):
|
||||
@@ -25,11 +26,11 @@ class Curl(object):
|
||||
raise
|
||||
respinfo = {}
|
||||
for line in p.stdout:
|
||||
line = line.strip()
|
||||
line = u(line.strip())
|
||||
if re.match('^HTTP.*? 200 OK$', line):
|
||||
break
|
||||
for line in p.stdout:
|
||||
line = line.strip().split(":", 1)
|
||||
line = u(line.strip()).split(":", 1)
|
||||
if len(line) == 2:
|
||||
respinfo[line[0].strip().lower()] = line[1].strip()
|
||||
return respinfo
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import os
|
||||
import re
|
||||
import ConfigParser
|
||||
try:
|
||||
import ConfigParser
|
||||
except:
|
||||
import configparser as ConfigParser
|
||||
|
||||
# pythonbrew version
|
||||
VERSION = "0.7.2"
|
||||
|
||||
if os.environ.has_key("PYTHONBREW_ROOT"):
|
||||
ROOT = os.environ["PYTHONBREW_ROOT"]
|
||||
else:
|
||||
# pythonbrew root path
|
||||
ROOT = os.environ.get("PYTHONBREW_ROOT")
|
||||
if not ROOT:
|
||||
ROOT = os.path.join(os.environ["HOME"],".pythonbrew")
|
||||
|
||||
# pythonbrew installer root path
|
||||
INSTALLER_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# directories
|
||||
|
||||
@@ -2,6 +2,7 @@ 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
|
||||
from pythonbrew.util import u
|
||||
|
||||
def get_headerinfo_from_url(url):
|
||||
c = Curl()
|
||||
@@ -9,7 +10,7 @@ def get_headerinfo_from_url(url):
|
||||
|
||||
def get_stable_version():
|
||||
c = Curl()
|
||||
return c.read(PYTHONBREW_STABLE_VERSION_URL).strip()
|
||||
return u(c.read(PYTHONBREW_STABLE_VERSION_URL).strip())
|
||||
|
||||
class Downloader(object):
|
||||
def download(self, msg, url, path):
|
||||
@@ -24,6 +25,4 @@ def get_pythonbrew_update_url(version):
|
||||
return PYTHONBREW_UPDATE_URL_PYPI % (version)
|
||||
|
||||
def get_python_version_url(version):
|
||||
if PYTHON_VERSION_URL.has_key(version):
|
||||
return PYTHON_VERSION_URL[version]
|
||||
return None
|
||||
return PYTHON_VERSION_URL.get(version)
|
||||
|
||||
@@ -8,6 +8,7 @@ from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
|
||||
PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\
|
||||
ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
|
||||
PATH_SCRIPTS_PYTHONBREW_INSTALLER
|
||||
import stat
|
||||
|
||||
class PythonbrewInstaller(object):
|
||||
"""pythonbrew installer:
|
||||
@@ -55,7 +56,8 @@ if __name__ == "__main__":
|
||||
%s %s/pythonbrew_main.py "$@"
|
||||
""" % (sys.executable, PATH_SCRIPTS))
|
||||
fp.close()
|
||||
os.chmod(PATH_BIN_PYTHONBREW, 0755)
|
||||
# mode 0755
|
||||
os.chmod(PATH_BIN_PYTHONBREW, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH)
|
||||
|
||||
# create a bashrc for pythonbrew
|
||||
fp = open(os.path.join(PATH_ETC,'bashrc'), 'w')
|
||||
|
||||
+21
-5
@@ -11,6 +11,7 @@ from subprocess import PIPE, Popen
|
||||
from pythonbrew.define import PATH_BIN, PATH_PYTHONS, PATH_ETC_CURRENT
|
||||
from pythonbrew.exceptions import ShellCommandException
|
||||
from pythonbrew.log import logger
|
||||
import sys
|
||||
|
||||
def size_format(b):
|
||||
kb = 1000
|
||||
@@ -76,8 +77,9 @@ def is_python26(version):
|
||||
def makedirs(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError, (e, es):
|
||||
if errno.EEXIST != e:
|
||||
except OSError:
|
||||
e = sys.exc_info()[1]
|
||||
if errno.EEXIST != e.errno:
|
||||
raise
|
||||
|
||||
def symlink(src, dst):
|
||||
@@ -89,8 +91,9 @@ def symlink(src, dst):
|
||||
def unlink(path):
|
||||
try:
|
||||
os.unlink(path)
|
||||
except OSError, (e, es):
|
||||
if errno.ENOENT != e:
|
||||
except OSError:
|
||||
e = sys.exc_info()[1]
|
||||
if errno.ENOENT != e.errno:
|
||||
raise
|
||||
|
||||
def rm_r(path):
|
||||
@@ -166,7 +169,8 @@ def untar_file(filename, location):
|
||||
else:
|
||||
try:
|
||||
fp = tar.extractfile(member)
|
||||
except (KeyError, AttributeError), e:
|
||||
except (KeyError, AttributeError):
|
||||
e = sys.exc_info()[1]
|
||||
# Some corrupt tar files seem to produce this
|
||||
# (specifically bad symlinks)
|
||||
logger.error('In the tar file %s the member %s is invalid: %s'
|
||||
@@ -218,6 +222,18 @@ def fileurl_to_path(url):
|
||||
url = '/' + url[len('file:'):].lstrip('/')
|
||||
return urllib.unquote(url)
|
||||
|
||||
def u(val):
|
||||
"""to unicode
|
||||
"""
|
||||
try:
|
||||
# for python3
|
||||
if type(val) == bytes:
|
||||
return val.decode()
|
||||
except:
|
||||
if type(val) == str:
|
||||
return val.decode("utf-8")
|
||||
return val
|
||||
|
||||
class Subprocess(object):
|
||||
def __init__(self, log=None, shell=True, cwd=None, print_cmd=False):
|
||||
self._log = log
|
||||
|
||||
Reference in New Issue
Block a user