mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 15:20:16 +00:00
added some function to bashrc. fixed issue 2.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import off, symlink, Package
|
||||
@@ -13,13 +12,13 @@ class SwitchCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.error("Unrecognized command line argument: argument not found.")
|
||||
logger.info("Unrecognized command line argument: argument not found.")
|
||||
sys.exit(1)
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
pkgdir = "%s/%s" % (PATH_PYTHONS, pkgname)
|
||||
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgdir):
|
||||
logger.error("`%s` is not installed." % pkgname)
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
self._switch_dir(pkgdir)
|
||||
logger.info("Switched to %s" % pkgname)
|
||||
@@ -27,15 +26,13 @@ class SwitchCommand(Command):
|
||||
def _switch_dir(self, pkgdir):
|
||||
off()
|
||||
symlink(pkgdir, "%s/current" % PATH_PYTHONS)
|
||||
for root, dirs, files in os.walk("%s/current/bin/" % PATH_PYTHONS):
|
||||
for f in files:
|
||||
symlink("%s%s" % (root, f), "%s/%s" % (PATH_BIN, f))
|
||||
break
|
||||
# I want better code
|
||||
if not os.path.isfile("%s/python" % PATH_BIN):
|
||||
if os.path.isfile("%s/python3" % PATH_BIN):
|
||||
symlink(os.path.realpath("%s/python3" % PATH_BIN), "%s/python" % PATH_BIN)
|
||||
elif os.path.isfile("%s/python3.0" % PATH_BIN):
|
||||
symlink(os.path.realpath("%s/python3.0" % PATH_BIN), "%s/python" % PATH_BIN)
|
||||
|
||||
# I want better code...
|
||||
current_bin = os.path.join(PATH_PYTHONS,'current','bin')
|
||||
if not os.path.isfile(os.path.join(current_bin,"python")):
|
||||
if os.path.isfile(os.path.join(current_bin,"python3")):
|
||||
symlink(os.path.realpath("%s/python3" % current_bin), os.path.join(PATH_BIN,"python"))
|
||||
elif os.path.isfile(os.path.join(current_bin,"python3.0")):
|
||||
symlink(os.path.realpath("%s/python3.0" % current_bin), os.path.join(PATH_BIN,"python"))
|
||||
|
||||
SwitchCommand()
|
||||
|
||||
@@ -6,8 +6,7 @@ from pythonbrew.define import PATH_DISTS, VERSION, ROOT,\
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader, get_pythonbrew_update_url,\
|
||||
get_response_from_url, get_stable_version
|
||||
from pythonbrew.util import rm_r, unpack_downloadfile, Link, is_gzip
|
||||
from pythonbrew.installer import PythonbrewInstaller
|
||||
from pythonbrew.util import rm_r, unpack_downloadfile, Link, is_gzip, Subprocess
|
||||
|
||||
class UpdateCommand(Command):
|
||||
name = "update"
|
||||
@@ -51,9 +50,9 @@ class UpdateCommand(Command):
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
installer_path = "%s/pythonbrew" % (extract_dir)
|
||||
logger.info("Installing %s into %s" % (extract_dir, ROOT))
|
||||
PythonbrewInstaller().install(installer_path)
|
||||
s = Subprocess()
|
||||
s.check_call('%s %s/pythonbrew_install.py --upgrade' % (sys.executable, extract_dir))
|
||||
except:
|
||||
logger.error("Failed to update pythonbrew.")
|
||||
raise
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class Curl(object):
|
||||
def __init__(self):
|
||||
returncode = subprocess.call("command -v curl > /dev/null", shell=True)
|
||||
if returncode:
|
||||
logger.info("pythonbrew required curl. curl was not found in your path.")
|
||||
sys.exit(1)
|
||||
|
||||
def read(self, url):
|
||||
p = Popen("curl -skL %s" % url, stdout=PIPE, shell=True)
|
||||
p.wait()
|
||||
if p.returncode:
|
||||
raise
|
||||
return p.stdout.read()
|
||||
|
||||
def readheader(self, url):
|
||||
p = Popen("curl --head -skL %s" % url, stdout=PIPE, shell=True)
|
||||
p.wait()
|
||||
if p.returncode:
|
||||
raise
|
||||
respinfo = {}
|
||||
for line in p.stdout:
|
||||
line = line.strip().split(":", 1)
|
||||
if len(line) == 2:
|
||||
respinfo[line[0].strip().lower()] = line[1].strip()
|
||||
return respinfo
|
||||
|
||||
def fetch(self, url, filename):
|
||||
p = Popen("curl -# -kL %s -o %s" % (url, filename), shell=True)
|
||||
p.wait()
|
||||
if p.returncode:
|
||||
raise
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
VERSION = "0.6.1"
|
||||
VERSION = "0.6.2"
|
||||
|
||||
if os.environ.has_key("PYTHONBREW_ROOT"):
|
||||
ROOT = os.environ["PYTHONBREW_ROOT"]
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
|
||||
class BuildingException(Exception):
|
||||
"""General exception during building"""
|
||||
|
||||
class ShellCommandException(Exception):
|
||||
"""General exception during shell command"""
|
||||
|
||||
@@ -52,6 +52,9 @@ The default help messages will popup and tell you what to do!
|
||||
Enjoy pythonbrew at %(ROOT)s!!
|
||||
""" % {'ROOT':ROOT, 'yourshrc':yourshrc, 'shrc':shrc, 'PATH_ETC':PATH_ETC})
|
||||
|
||||
def upgrade_pythonbrew():
|
||||
PythonbrewInstaller().install(INSTALLER_ROOT)
|
||||
|
||||
class PythonbrewInstaller(object):
|
||||
def install(self, installer_root):
|
||||
makedirs(PATH_PYTHONS)
|
||||
@@ -88,7 +91,11 @@ if __name__ == "__main__":
|
||||
os.chmod(PATH_BIN_PYTHONBREW, 0755)
|
||||
symlink(PATH_BIN_PYTHONBREW, PATH_BIN_PYBREW) # pybrew is symbolic pythonbrew
|
||||
|
||||
os.system("echo 'export PATH=%s/bin:%s/current/bin:${PATH}' > %s/bashrc" % (ROOT, PATH_PYTHONS, PATH_ETC))
|
||||
fp = open(os.path.join(PATH_ETC,'bashrc'), 'w')
|
||||
for line in open(os.path.join(installer_root,'scripts','bashrc')):
|
||||
line = line.replace('@ROOT@', ROOT)
|
||||
fp.write(line)
|
||||
fp.close()
|
||||
os.system("echo 'setenv PATH %s/bin:%s/current/bin:$PATH' > %s/cshrc" % (ROOT, PATH_PYTHONS, PATH_ETC))
|
||||
|
||||
class PythonInstaller(object):
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
PYTHONBREW_ROOT="@ROOT@"
|
||||
PYTHONBREW_ETC="$PYTHONBREW_ROOT/etc"
|
||||
|
||||
export PATH=$PYTHONBREW_ROOT/bin:$PYTHONBREW_ROOT/pythons/current/bin:${PATH}
|
||||
|
||||
__pythonbrew_reload()
|
||||
{
|
||||
if [[ -s "$PYTHONBREW_ETC/bashrc" ]] ; then
|
||||
source "$PYTHONBREW_ETC/bashrc"
|
||||
fi
|
||||
}
|
||||
|
||||
pythonbrew()
|
||||
{
|
||||
command pythonbrew "$@"
|
||||
case $1 in
|
||||
update) __pythonbrew_reload ;;
|
||||
esac
|
||||
hash -r
|
||||
}
|
||||
+3
-3
@@ -5,7 +5,7 @@ import subprocess
|
||||
import re
|
||||
import posixpath
|
||||
from pythonbrew.define import PATH_BIN, PATH_PYTHONS
|
||||
from pythonbrew.exceptions import BuildingException
|
||||
from pythonbrew.exceptions import ShellCommandException
|
||||
from pythonbrew.log import logger
|
||||
import tarfile
|
||||
import platform
|
||||
@@ -183,7 +183,7 @@ def unpack_downloadfile(content_type, download_file, target_dir):
|
||||
logger.error("Cannot determine archive format of %s" % download_file)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class Subprocess(object):
|
||||
def __init__(self, log=None, shell=True, cwd=None, print_cmd=False):
|
||||
self._log = log
|
||||
@@ -205,7 +205,7 @@ class Subprocess(object):
|
||||
cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log)
|
||||
retcode = subprocess.call(cmd, shell=self._shell, cwd=self._cwd)
|
||||
if retcode != 0:
|
||||
raise BuildingException()
|
||||
raise ShellCommandException('Failed to `%s` command' % cmd)
|
||||
|
||||
class Package(object):
|
||||
def __init__(self, name):
|
||||
|
||||
Reference in New Issue
Block a user