mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
add systemwide install support
This commit is contained in:
+14
-16
@@ -5,7 +5,7 @@ from pythonbrew.define import PATH_PYTHONS, PATH_VENVS, PATH_HOME_ETC_VENV,\
|
||||
PATH_ETC, VIRTUALENV_DLSITE, PATH_DISTS
|
||||
from pythonbrew.util import Package, \
|
||||
is_installed, get_installed_pythons_pkgname, get_using_python_pkgname,\
|
||||
untar_file
|
||||
untar_file, Subprocess, rm_r
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader
|
||||
|
||||
@@ -92,32 +92,30 @@ class VenvCommand(Command):
|
||||
untar_file(download_file, self._venv_dir)
|
||||
|
||||
def run_command_create(self, options, args):
|
||||
virtualenv_options = ''
|
||||
virtualenv_options = []
|
||||
if options.no_site_packages:
|
||||
virtualenv_options += '--no-site-packages'
|
||||
virtualenv_options.append('--no-site-packages')
|
||||
|
||||
output = []
|
||||
for arg in args[1:]:
|
||||
target_dir = os.path.join(self._workon_home, arg)
|
||||
output.append("""\
|
||||
echo '# Create `%(arg)s` environment into %(workon_home)s'
|
||||
%(py)s %(venv)s -p '%(target_py)s' %(options)s '%(target_dir)s'
|
||||
""" % {'arg': arg, 'workon_home': self._workon_home, 'py': self._py, 'venv': self._venv, 'target_py': self._target_py, 'options': virtualenv_options, 'target_dir': target_dir})
|
||||
self._write(''.join(output))
|
||||
logger.log("# Create `%s` environment into %s" % (arg, self._workon_home))
|
||||
# make command
|
||||
cmd = [self._py, self._venv, '-p', self._target_py]
|
||||
cmd.extend(virtualenv_options)
|
||||
cmd.append(target_dir)
|
||||
# create environment
|
||||
s = Subprocess(verbose=True)
|
||||
s.call(cmd)
|
||||
|
||||
def run_command_delete(self, options, args):
|
||||
output = []
|
||||
for arg in args[1:]:
|
||||
target_dir = os.path.join(self._workon_home, arg)
|
||||
if not os.path.isdir(target_dir):
|
||||
logger.error('%s already does not exist.' % target_dir)
|
||||
else:
|
||||
output.append("""\
|
||||
echo '# Delete `%(arg)s` environment in %(workon_home)s'
|
||||
rm -rf '%(target_dir)s'
|
||||
""" % {'arg': arg, 'workon_home': self._workon_home, 'target_dir': target_dir})
|
||||
if output:
|
||||
self._write(''.join(output))
|
||||
logger.log('# Delete `%s` environment in %s' % (arg, self._workon_home))
|
||||
# make command
|
||||
rm_r(target_dir)
|
||||
|
||||
def run_command_use(self, options, args):
|
||||
if len(args) < 2:
|
||||
|
||||
+15
-3
@@ -11,8 +11,8 @@ if [ -z "${PATH_HOME}" ] ; then
|
||||
fi
|
||||
PATH_HOME_ETC="$PATH_HOME/etc"
|
||||
|
||||
# exec
|
||||
pythonbrew="$PATH_ROOT/bin/pythonbrew"
|
||||
# py file
|
||||
PY_PYTHONBREW="$PATH_ROOT/bin/pythonbrew"
|
||||
|
||||
# functions
|
||||
__pythonbrew_set_default()
|
||||
@@ -103,7 +103,7 @@ __pythonbrew_find_command()
|
||||
done
|
||||
}
|
||||
|
||||
pythonbrew()
|
||||
__pythonbrew_run()
|
||||
{
|
||||
__pythonbrew_find_command "$@"
|
||||
case $command_name in
|
||||
@@ -117,10 +117,22 @@ pythonbrew()
|
||||
builtin hash -r
|
||||
}
|
||||
|
||||
pythonbrew()
|
||||
{
|
||||
pythonbrew=$PY_PYTHONBREW
|
||||
__pythonbrew_run "$@"
|
||||
}
|
||||
|
||||
pybrew()
|
||||
{
|
||||
pythonbrew "$@"
|
||||
}
|
||||
|
||||
sudopybrew()
|
||||
{
|
||||
pythonbrew="sudo PYTHONBREW_ROOT=$PATH_ROOT $PY_PYTHONBREW"
|
||||
__pythonbrew_run "$@"
|
||||
}
|
||||
|
||||
# main
|
||||
__pythonbrew_set_current_path
|
||||
|
||||
@@ -3,7 +3,7 @@ from pythonbrew.log import logger
|
||||
from pythonbrew.define import INSTALLER_ROOT, ROOT, PATH_ETC
|
||||
|
||||
def install_pythonbrew():
|
||||
PythonbrewInstaller().install(INSTALLER_ROOT)
|
||||
PythonbrewInstaller.install(INSTALLER_ROOT)
|
||||
# for bash
|
||||
shrc = yourshrc = "bashrc"
|
||||
logger.log("""
|
||||
@@ -33,4 +33,30 @@ Enjoy pythonbrew at %(ROOT)s!!
|
||||
""" % {'ROOT':ROOT, 'yourshrc':yourshrc, 'shrc':shrc, 'PATH_ETC':PATH_ETC})
|
||||
|
||||
def upgrade_pythonbrew():
|
||||
PythonbrewInstaller().install(INSTALLER_ROOT)
|
||||
PythonbrewInstaller.install(INSTALLER_ROOT)
|
||||
|
||||
def systemwide_pythonbrew():
|
||||
PythonbrewInstaller.install(INSTALLER_ROOT)
|
||||
PythonbrewInstaller.systemwide_install()
|
||||
logger.log("""
|
||||
Well-done! Congratulations!
|
||||
|
||||
The pythonbrew is installed as:
|
||||
|
||||
%(ROOT)s
|
||||
|
||||
After that, exit this shell, start a new one, and install some fresh
|
||||
pythons:
|
||||
|
||||
pythonbrew install 2.7.2
|
||||
pythonbrew install 3.2
|
||||
|
||||
For further instructions, run:
|
||||
|
||||
pythonbrew help
|
||||
|
||||
The default help messages will popup and tell you what to do!
|
||||
|
||||
Enjoy pythonbrew at %(ROOT)s!!
|
||||
""" % {'ROOT':ROOT})
|
||||
|
||||
@@ -6,15 +6,16 @@ from pythonbrew.util import makedirs, rm_r
|
||||
from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
|
||||
PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\
|
||||
PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\
|
||||
ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
|
||||
PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC
|
||||
PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
|
||||
PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC, ROOT
|
||||
import stat
|
||||
|
||||
class PythonbrewInstaller(object):
|
||||
"""pythonbrew installer:
|
||||
"""
|
||||
|
||||
def install(self, installer_root):
|
||||
@staticmethod
|
||||
def install(installer_root):
|
||||
# create directories
|
||||
makedirs(PATH_PYTHONS)
|
||||
makedirs(PATH_BUILD)
|
||||
@@ -62,12 +63,43 @@ if __name__ == "__main__":
|
||||
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')
|
||||
for line in open(os.path.join(installer_root,'etc','bashrc')):
|
||||
line = line.replace('@ROOT@', ROOT)
|
||||
fp.write(line)
|
||||
fp.close()
|
||||
shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc'))
|
||||
|
||||
# copy config.cfg
|
||||
shutil.copy(os.path.join(installer_root,'etc','config.cfg'), PATH_ETC_CONFIG)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def systemwide_install():
|
||||
profile = """\
|
||||
#begin-pythonbrew
|
||||
if [ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
||||
export PYTHONBREW_ROOT=%(root)s
|
||||
source "${PYTHONBREW_ROOT}/etc/bashrc"
|
||||
fi
|
||||
#end-pythonbrew
|
||||
""" % {'root': ROOT}
|
||||
|
||||
if os.path.isdir('/etc/profile.d'):
|
||||
fp = open('/etc/profile.d/pythonbrew.sh', 'w')
|
||||
fp.write(profile)
|
||||
fp.close()
|
||||
elif os.path.isfile('/etc/profile'):
|
||||
output = []
|
||||
is_copy = True
|
||||
fp = open('/etc/profile', 'r')
|
||||
for line in fp:
|
||||
if line.startswith('#begin-pythonbrew'):
|
||||
is_copy = False
|
||||
continue
|
||||
elif line.startswith('#end-pythonbrew'):
|
||||
is_copy = True
|
||||
continue
|
||||
if is_copy:
|
||||
output.append(line)
|
||||
fp.close()
|
||||
output.append(profile)
|
||||
|
||||
fp = open('/etc/profile', 'w')
|
||||
fp.write(''.join(output))
|
||||
fp.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user