mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
release 0.9
This commit is contained in:
+42
-15
@@ -9,7 +9,8 @@ import platform
|
||||
import urllib
|
||||
import subprocess
|
||||
import shlex
|
||||
from pythonbrew.define import PATH_BIN, PATH_ETC_CURRENT
|
||||
import select
|
||||
from pythonbrew.define import PATH_BIN, PATH_ETC_CURRENT, PATH_PYTHONS
|
||||
from pythonbrew.exceptions import ShellCommandException
|
||||
from pythonbrew.log import logger
|
||||
|
||||
@@ -93,12 +94,8 @@ def is_python32(version):
|
||||
return version >= '3.2' and version < '3.3'
|
||||
|
||||
def makedirs(path):
|
||||
try:
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
except OSError:
|
||||
e = sys.exc_info()[1]
|
||||
if errno.EEXIST != e.errno:
|
||||
raise
|
||||
|
||||
def symlink(src, dst):
|
||||
try:
|
||||
@@ -212,12 +209,29 @@ def extract_downloadfile(content_type, download_file, target_dir):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_current_python_path():
|
||||
"""return: python path or ''
|
||||
"""
|
||||
def get_using_python_path():
|
||||
p = subprocess.Popen('command -v python', stdout=subprocess.PIPE, shell=True)
|
||||
return to_str(p.communicate()[0].strip())
|
||||
|
||||
def get_using_python_pkgname():
|
||||
"""return: Python-<VERSION> or None"""
|
||||
path = get_using_python_path()
|
||||
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||
if path and os.path.samefile(path, os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
||||
return d
|
||||
return None
|
||||
|
||||
def get_installed_pythons_pkgname():
|
||||
"""Get the installed python versions list."""
|
||||
return [d for d in sorted(os.listdir(PATH_PYTHONS))]
|
||||
|
||||
def is_installed(name):
|
||||
pkgname = Package(name).name
|
||||
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgdir):
|
||||
return False
|
||||
return True
|
||||
|
||||
def set_current_path(path):
|
||||
fp = open(PATH_ETC_CURRENT, 'w')
|
||||
fp.write('PATH_PYTHONBREW="%s"\n' % (path))
|
||||
@@ -254,6 +268,16 @@ def is_str(val):
|
||||
return isinstance(val, str)
|
||||
return False
|
||||
|
||||
def bltin_any(iter):
|
||||
try:
|
||||
return any(iter)
|
||||
except:
|
||||
# python2.4
|
||||
for it in iter:
|
||||
if it:
|
||||
return True
|
||||
return False
|
||||
|
||||
class Subprocess(object):
|
||||
def __init__(self, log=None, cwd=None, verbose=False, debug=False):
|
||||
self._log = log
|
||||
@@ -285,13 +309,16 @@ class Subprocess(object):
|
||||
fp = ((self._log and open(self._log, 'a')) or None)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd)
|
||||
while p.returncode is None:
|
||||
while bltin_any(select.select([p.stdout], [], [])):
|
||||
line = to_str(p.stdout.readline())
|
||||
if not line:
|
||||
break
|
||||
if self._verbose:
|
||||
logger.info(line.strip())
|
||||
if fp:
|
||||
fp.write(line)
|
||||
fp.flush()
|
||||
p.poll()
|
||||
line = to_str(p.stdout.readline())
|
||||
if self._verbose:
|
||||
logger.info(line.strip())
|
||||
if fp:
|
||||
fp.write(line)
|
||||
fp.flush()
|
||||
if fp:
|
||||
fp.close()
|
||||
return p.returncode
|
||||
|
||||
Reference in New Issue
Block a user