mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 15:20:16 +00:00
release 0.10
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE, PATH_DISTS
|
||||
from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE
|
||||
from pythonbrew.util import Package, get_using_python_pkgname, Link, is_installed
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader
|
||||
@@ -28,7 +28,7 @@ class BuildoutCommand(Command):
|
||||
else:
|
||||
pkgname = get_using_python_pkgname()
|
||||
if not is_installed(pkgname):
|
||||
logger.info('%s is not installed.' % pkgname)
|
||||
logger.error('`%s` is not installed.' % pkgname)
|
||||
sys.exit(1)
|
||||
logger.info('Using %s' % pkgname)
|
||||
|
||||
@@ -38,20 +38,21 @@ class BuildoutCommand(Command):
|
||||
# Download bootstrap.py
|
||||
download_url = BOOTSTRAP_DLSITE
|
||||
filename = Link(download_url).filename
|
||||
bootstrap = os.path.join(PATH_DISTS, filename)
|
||||
bootstrap = os.path.join(os.getcwd(), filename) # fetching into current directory
|
||||
try:
|
||||
d = Downloader()
|
||||
d.download(filename, download_url, bootstrap)
|
||||
except:
|
||||
logger.error("Failed to download. `%s`" % download_url)
|
||||
e = sys.exc_info()[1]
|
||||
logger.error("%s" % (e))
|
||||
sys.exit(1)
|
||||
|
||||
# Using bootstrap.py
|
||||
# call bootstrap.py
|
||||
if subprocess.call([python, bootstrap, '-d']):
|
||||
logger.error('Failed to bootstrap.')
|
||||
sys.exit(1)
|
||||
|
||||
# Using buildout
|
||||
# call buildout
|
||||
subprocess.call(['./bin/buildout'])
|
||||
|
||||
BuildoutCommand()
|
||||
|
||||
@@ -17,11 +17,11 @@ class HelpCommand(Command):
|
||||
command.parser.print_help()
|
||||
return
|
||||
parser.print_help()
|
||||
logger.info("\nCommands available:")
|
||||
logger.log("\nCommands available:")
|
||||
commands = [command_dict[key] for key in sorted(command_dict.keys())]
|
||||
for command in commands:
|
||||
logger.info(" %s: %s" % (command.name, command.summary))
|
||||
logger.info("\nFurther Instructions:")
|
||||
logger.info(" https://github.com/utahta/pythonbrew")
|
||||
logger.log(" %s: %s" % (command.name, command.summary))
|
||||
logger.log("\nFurther Instructions:")
|
||||
logger.log(" https://github.com/utahta/pythonbrew")
|
||||
|
||||
HelpCommand()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.installer.pythoninstaller import PythonInstaller,\
|
||||
PythonInstallerMacOSX
|
||||
from pythonbrew.util import is_macosx
|
||||
@@ -63,22 +63,22 @@ class InstallCommand(Command):
|
||||
)
|
||||
|
||||
def run_command(self, options, args):
|
||||
if args:
|
||||
# installing python
|
||||
for arg in args:
|
||||
try:
|
||||
if is_macosx():
|
||||
p = PythonInstallerMacOSX(arg, options)
|
||||
else:
|
||||
p = PythonInstaller(arg, options)
|
||||
p.install()
|
||||
except UnknownVersionException:
|
||||
continue
|
||||
except AlreadyInstalledException:
|
||||
continue
|
||||
except NotSupportedVersionException:
|
||||
continue
|
||||
else:
|
||||
logger.info("Unknown python version.")
|
||||
if not args:
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
# installing python
|
||||
for arg in args:
|
||||
try:
|
||||
if is_macosx():
|
||||
p = PythonInstallerMacOSX(arg, options)
|
||||
else:
|
||||
p = PythonInstaller(arg, options)
|
||||
p.install()
|
||||
except UnknownVersionException:
|
||||
continue
|
||||
except AlreadyInstalledException:
|
||||
continue
|
||||
except NotSupportedVersionException:
|
||||
continue
|
||||
|
||||
InstallCommand()
|
||||
|
||||
@@ -3,8 +3,7 @@ import re
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\
|
||||
PATH_PYTHONS
|
||||
from pythonbrew.util import Package, get_using_python_pkgname,\
|
||||
get_using_python_path
|
||||
from pythonbrew.util import Package, get_using_python_pkgname
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class ListCommand(Command):
|
||||
@@ -36,18 +35,16 @@ class ListCommand(Command):
|
||||
self.installed(options, args)
|
||||
|
||||
def installed(self, options, args):
|
||||
logger.info('# installed pythons')
|
||||
logger.log("# pythonbrew pythons")
|
||||
cur = get_using_python_pkgname()
|
||||
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||
if cur and cur == d:
|
||||
logger.info('%s (*)' % d)
|
||||
logger.log(' %s (*)' % d)
|
||||
else:
|
||||
logger.info('%s' % d)
|
||||
if not cur:
|
||||
logger.info('%s (*)' % get_using_python_path())
|
||||
logger.log(' %s' % d)
|
||||
|
||||
def available_install(self, options, args):
|
||||
logger.info('# available install pythons')
|
||||
logger.log('# Pythons')
|
||||
if args:
|
||||
pkg = Package(args[0])
|
||||
_re = re.compile(r"%s" % pkg.name)
|
||||
@@ -57,12 +54,12 @@ class ListCommand(Command):
|
||||
pkgs.append(pkgname)
|
||||
if pkgs:
|
||||
for pkgname in pkgs:
|
||||
logger.info("%s" % pkgname)
|
||||
logger.log("%s" % pkgname)
|
||||
else:
|
||||
logger.info("Python version not found. `%s`" % pkg.name)
|
||||
logger.error("`%s` was not found." % pkg.name)
|
||||
else:
|
||||
for pkgname in self._get_packages_name(options):
|
||||
logger.info("%s" % pkgname)
|
||||
logger.log("%s" % pkgname)
|
||||
|
||||
def _get_packages_name(self, options):
|
||||
return ["Python-%s" % version for version in sorted(PYTHON_VERSION_URL.keys())
|
||||
|
||||
@@ -32,12 +32,12 @@ class PyCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.info("Unrecognized command line argument: argument not found.")
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
pythons = self._get_pythons(options.pythons)
|
||||
for d in pythons:
|
||||
if options.verbose:
|
||||
logger.info('*** %s ***' % d)
|
||||
logger.info('`%s` running...' % d)
|
||||
path = os.path.join(PATH_PYTHONS, d, 'bin', args[0])
|
||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||
subprocess.call([path] + args[1:])
|
||||
@@ -46,7 +46,7 @@ class PyCommand(Command):
|
||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||
subprocess.call([path] + args)
|
||||
else:
|
||||
logger.info('%s: No such file or directory.' % path)
|
||||
logger.error('%s: No such file or directory.' % path)
|
||||
|
||||
def _get_pythons(self, _pythons):
|
||||
pythons = [Package(p).name for p in _pythons]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.define import PATH_PYTHONS
|
||||
from pythonbrew.util import Package, set_current_path, is_installed
|
||||
from pythonbrew.log import logger
|
||||
|
||||
@@ -12,16 +12,16 @@ class SwitchCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.info("Unrecognized command line argument: argument not found.")
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
if not is_installed(pkgname):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
logger.error("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
|
||||
|
||||
set_current_path('%s:%s' % (PATH_BIN, pkgbin))
|
||||
set_current_path(pkgbin)
|
||||
|
||||
logger.info("Switched to %s" % pkgname)
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import Package, symlink, unlink
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_VENVS
|
||||
from pythonbrew.util import Package, symlink, unlink, get_using_python_pkgname,\
|
||||
is_installed
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class SymlinkCommand(Command):
|
||||
@@ -32,6 +34,12 @@ class SymlinkCommand(Command):
|
||||
default=None,
|
||||
help="Use as default the specified python version."
|
||||
)
|
||||
self.parser.add_option(
|
||||
"-v", "--venv",
|
||||
dest="venv",
|
||||
default=None,
|
||||
help="Use the virtual environment python."
|
||||
)
|
||||
|
||||
def run_command(self, options, args):
|
||||
if options.default:
|
||||
@@ -43,6 +51,28 @@ class SymlinkCommand(Command):
|
||||
self._symlink(bin, bin, pkgname)
|
||||
else:
|
||||
self._symlink('python', 'py', pkgname)
|
||||
elif options.venv:
|
||||
if options.pythons:
|
||||
pkgname = Package(options.pythons[0]).name
|
||||
else:
|
||||
pkgname = get_using_python_pkgname()
|
||||
if not is_installed(pkgname):
|
||||
logger.error('`%s` is not installed.')
|
||||
sys.exit(1)
|
||||
|
||||
venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
|
||||
venv_dir = os.path.join(venv_pkgdir, options.venv)
|
||||
if not os.path.isdir(venv_dir):
|
||||
logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir))
|
||||
sys.exit(1)
|
||||
pkg = Package(pkgname)
|
||||
if args:
|
||||
bin = args[0]
|
||||
dstbin = '%s%s-%s' % (bin, pkg.version, options.venv)
|
||||
self._symlink(bin, dstbin, pkgname)
|
||||
else:
|
||||
dstbin = 'py%s-%s' % (pkg.version, options.venv)
|
||||
self._symlink('python', dstbin, pkgname)
|
||||
else:
|
||||
pythons = self._get_pythons(options.pythons)
|
||||
for pkgname in pythons:
|
||||
@@ -75,7 +105,7 @@ class SymlinkCommand(Command):
|
||||
if os.path.isfile(src):
|
||||
symlink(src, dst)
|
||||
else:
|
||||
logger.info("%s: File not found" % src)
|
||||
logger.error("%s was not found in your path." % src)
|
||||
|
||||
def _get_pythons(self, _pythons):
|
||||
"""Get the installed python versions list.
|
||||
|
||||
@@ -19,7 +19,7 @@ class UninstallCommand(Command):
|
||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||
venvpath = os.path.join(PATH_VENVS, pkgname)
|
||||
if not is_installed(pkgname):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
logger.error("`%s` is not installed." % pkgname)
|
||||
continue
|
||||
if get_using_python_pkgname() == pkgname:
|
||||
off()
|
||||
|
||||
@@ -65,7 +65,7 @@ class UpdateCommand(Command):
|
||||
except:
|
||||
logger.error("Failed to download. `%s`" % download_url)
|
||||
sys.exit(1)
|
||||
logger.info("The config.cfg has been updated.")
|
||||
logger.log("The config.cfg has been updated.")
|
||||
|
||||
def _update_pythonbrew(self, options, args):
|
||||
if options.master:
|
||||
@@ -81,7 +81,7 @@ class UpdateCommand(Command):
|
||||
|
||||
download_url = get_pythonbrew_update_url(version)
|
||||
if not download_url:
|
||||
logger.error("`%s` of pythonbrew not found." % version)
|
||||
logger.error("`pythonbrew-%s` was not found in pypi." % version)
|
||||
sys.exit(1)
|
||||
headinfo = get_headerinfo_from_url(download_url)
|
||||
content_type = headinfo['content-type']
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_ETC_TEMP
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_HOME_ETC_TEMP
|
||||
from pythonbrew.util import Package
|
||||
from pythonbrew.log import logger
|
||||
|
||||
@@ -12,24 +12,23 @@ class UseCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.info("Unrecognized command line argument: argument not found.")
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgdir):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
logger.error("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
pkgbin = os.path.join(pkgdir,'bin')
|
||||
|
||||
self._set_temp('%s:%s' % (PATH_BIN, pkgbin))
|
||||
self._set_temp(pkgbin)
|
||||
|
||||
logger.info("Using `%s`" % pkgname)
|
||||
|
||||
def _set_temp(self, path):
|
||||
fp = open(PATH_ETC_TEMP, 'w')
|
||||
fp.write('PATH_PYTHONBREW="%s"\n' % (path))
|
||||
fp = open(PATH_HOME_ETC_TEMP, 'w')
|
||||
fp.write('PATH_PYTHONBREW_TEMP="%s"\n' % (path))
|
||||
fp.close()
|
||||
|
||||
|
||||
UseCommand()
|
||||
|
||||
+91
-85
@@ -1,10 +1,13 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_VENVS, PATH_ETC_VENV
|
||||
from pythonbrew.util import Subprocess, Package,\
|
||||
is_installed, get_installed_pythons_pkgname, get_using_python_pkgname
|
||||
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, Subprocess, rm_r
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader
|
||||
|
||||
class VenvCommand(Command):
|
||||
name = "venv"
|
||||
@@ -26,38 +29,30 @@ class VenvCommand(Command):
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Show the all python environments.",
|
||||
metavar='VERSION'
|
||||
)
|
||||
self.template_env = """export VIRTUALENVWRAPPER_PYTHON=%(venv_py)s
|
||||
export VIRTUALENVWRAPPER_VIRTUALENV=%(venv_venv)s
|
||||
export WORKON_HOME=%(workon_home)s
|
||||
export VIRTUALENVWRAPPER_HOOK_DIR=%(workon_home)s
|
||||
export VIRTUALENVWRAPPER_LOG_DIR=%(workon_home)s
|
||||
source %(venv_sh)s
|
||||
"""
|
||||
|
||||
self.parser.add_option(
|
||||
"-n", "--no-site-packages",
|
||||
dest="no_site_packages",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Don't give access to the global site-packages dir to the virtual environment.",
|
||||
)
|
||||
self._venv_dir = os.path.join(PATH_ETC, 'virtualenv')
|
||||
self._venv = os.path.join(self._venv_dir, 'virtualenv.py')
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.error('Unrecognized command line argument: ( see: \'pythonbrew help venv\' )')
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
cmd = args[0]
|
||||
if not cmd in ('create', 'delete', 'use', 'list'):
|
||||
logger.error('Unrecognized command line argument: ( see: \'pythonbrew help venv\' )')
|
||||
if not cmd in ('init', 'create', 'delete', 'use', 'list'):
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
# find python2
|
||||
venv_pkgname = None
|
||||
for pkgname in reversed(get_installed_pythons_pkgname()):
|
||||
# virtualenvwrapper require Python2
|
||||
venv_pkgver = Package(pkgname).version
|
||||
if venv_pkgver >= '2.4' and venv_pkgver < '3':
|
||||
venv_pkgname = pkgname
|
||||
break
|
||||
if not venv_pkgname:
|
||||
logger.error('Can not create virtual environment before installing a python2. Try \'pythonbrew install <python2.4 - 2.7>\'.')
|
||||
sys.exit(1)
|
||||
venv_dir = os.path.join(PATH_PYTHONS, venv_pkgname)
|
||||
venv_bin = os.path.join(venv_dir, 'bin')
|
||||
# initialize?
|
||||
if cmd == 'init':
|
||||
self.run_command_init()
|
||||
return
|
||||
|
||||
# target python interpreter
|
||||
if options.python:
|
||||
@@ -66,92 +61,103 @@ source %(venv_sh)s
|
||||
logger.error('%s is not installed.' % pkgname)
|
||||
sys.exit(1)
|
||||
else:
|
||||
# check using python under pythonbrew
|
||||
pkgname = get_using_python_pkgname()
|
||||
if not pkgname:
|
||||
logger.error('Can not use venv command before using a python. Try \'pythonbrew switch <some python>\'.')
|
||||
logger.error('Can not use venv command before switching a python. Try \'pythonbrew switch <version of python>\'.')
|
||||
sys.exit(1)
|
||||
self._pkgname = pkgname
|
||||
self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
|
||||
self._workon_home = os.path.join(PATH_VENVS, pkgname)
|
||||
self._venv_py = os.path.join(venv_bin, 'python')
|
||||
self._venv_venv = os.path.join(venv_bin, 'virtualenv')
|
||||
self._venv_sh = os.path.join(venv_bin, 'virtualenvwrapper.sh')
|
||||
self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
|
||||
|
||||
# has virtualenv & virtualenvwrapper?
|
||||
if not self._venv_venv or not self._venv_sh:
|
||||
logger.info('Installing virtualenv into %s' % venv_dir)
|
||||
s = Subprocess(verbose=True)
|
||||
s.shell('%s %s %s' % (os.path.join(venv_bin,'pip'), 'install', 'virtualenvwrapper'))
|
||||
# is already installed virtualenv?
|
||||
if not os.path.exists(self._venv):
|
||||
self.run_command_init()
|
||||
|
||||
# Create a shell script
|
||||
try:
|
||||
self.__getattribute__('run_command_%s' % cmd)(options, args)
|
||||
except:
|
||||
logger.error('`%s` command not found.' % cmd)
|
||||
self.__getattribute__('run_command_%s' % cmd)(options, args)
|
||||
|
||||
def run_command_init(self):
|
||||
if os.path.exists(self._venv):
|
||||
logger.info('venv command is already initialized.')
|
||||
return
|
||||
if not os.access(PATH_DISTS, os.W_OK):
|
||||
logger.error("Can not initialize venv command: Permission denied.")
|
||||
sys.exit(1)
|
||||
d = Downloader()
|
||||
download_file = os.path.join(PATH_DISTS, 'virtualenv.tar.gz')
|
||||
d.download('virtualenv.tar.gz', VIRTUALENV_DLSITE, download_file)
|
||||
logger.info('Extracting virtualenv into %s' % self._venv_dir)
|
||||
untar_file(download_file, self._venv_dir)
|
||||
|
||||
def run_command_create(self, options, args):
|
||||
output = [self.template_env % {'venv_py': self._venv_py,
|
||||
'venv_venv': self._venv_venv,
|
||||
'workon_home': self._workon_home,
|
||||
'venv_sh': self._venv_sh}]
|
||||
if not os.access(PATH_VENVS, os.W_OK):
|
||||
logger.error("Can not create a virtuale environment in %s.\nPermission denied." % PATH_VENVS)
|
||||
sys.exit(1)
|
||||
|
||||
virtualenv_options = []
|
||||
if options.no_site_packages:
|
||||
virtualenv_options.append('--no-site-packages')
|
||||
|
||||
for arg in args[1:]:
|
||||
output.append("""echo '# Create `%(arg)s` environment into %(workon_home)s'
|
||||
mkvirtualenv -p '%(target_py)s' '%(arg)s'
|
||||
""" % {'arg': arg,
|
||||
'workon_home': self._workon_home,
|
||||
'target_py': self._target_py})
|
||||
self._write(''.join(output))
|
||||
target_dir = os.path.join(self._workon_home, arg)
|
||||
logger.info("Creating `%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 = [self.template_env % {'venv_py': self._venv_py,
|
||||
'venv_venv': self._venv_venv,
|
||||
'workon_home': self._workon_home,
|
||||
'venv_sh': self._venv_sh}]
|
||||
for arg in args[1:]:
|
||||
output.append("""echo '# Delete `%(arg)s` environment in %(workon_home)s'
|
||||
rmvirtualenv '%(arg)s'
|
||||
""" % {'arg': arg,
|
||||
'workon_home': self._workon_home})
|
||||
self._write(''.join(output))
|
||||
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:
|
||||
if not os.access(target_dir, os.W_OK):
|
||||
logger.error("Can not delete %s.\nPermission denied." % target_dir)
|
||||
continue
|
||||
logger.info('Deleting `%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:
|
||||
logger.error("Unrecognized command line argument: ( 'pythonbrew venv use <project>' )")
|
||||
sys.exit(1)
|
||||
template = self.template_env + """echo '# Using `%(arg)s` environment (found in %(workon_home)s)'
|
||||
|
||||
activate = os.path.join(self._workon_home, args[1], 'bin', 'activate')
|
||||
if not os.path.exists(activate):
|
||||
logger.error('`%s` environment already does not exist. Try `pythonbrew venv create %s`.' % (args[1], args[1]))
|
||||
sys.exit(1)
|
||||
|
||||
self._write("""\
|
||||
echo '# Using `%(arg)s` environment (found in %(workon_home)s)'
|
||||
echo '# To leave an environment, simply run `deactivate`'
|
||||
workon '%(arg)s'
|
||||
"""
|
||||
self._write(template % {'venv_py': self._venv_py,
|
||||
'venv_venv': self._venv_venv,
|
||||
'workon_home': self._workon_home,
|
||||
'venv_sh': self._venv_sh,
|
||||
'arg': args[1]})
|
||||
|
||||
source '%(activate)s'
|
||||
""" % {'arg': args[1], 'workon_home': self._workon_home, 'activate': activate})
|
||||
|
||||
def run_command_list(self, options, args):
|
||||
template = self.template_env + """echo '# virtualenv for %(pkgname)s (found in %(workon_home)s)'
|
||||
workon
|
||||
"""
|
||||
if options.all:
|
||||
output = []
|
||||
for pkgname in get_installed_pythons_pkgname():
|
||||
workon_home = os.path.join(PATH_VENVS, pkgname)
|
||||
output.append(template % {'venv_py': self._venv_py,
|
||||
'venv_venv': self._venv_venv,
|
||||
'workon_home': workon_home,
|
||||
'venv_sh': self._venv_sh,
|
||||
'pkgname': pkgname})
|
||||
self._write(''.join(output))
|
||||
logger.log("# virtualenv for %(pkgname)s (found in %(workon_home)s)" % {'pkgname': pkgname, 'workon_home': workon_home})
|
||||
if os.path.isdir(workon_home):
|
||||
for d in sorted(os.listdir(workon_home)):
|
||||
if os.path.isdir(os.path.join(workon_home, d)):
|
||||
logger.log(d)
|
||||
else:
|
||||
self._write(template % {'venv_py': self._venv_py,
|
||||
'venv_venv': self._venv_venv,
|
||||
'workon_home': self._workon_home,
|
||||
'venv_sh': self._venv_sh,
|
||||
'pkgname': self._pkgname})
|
||||
logger.log("# virtualenv for %(pkgname)s (found in %(workon_home)s)" % {'pkgname': self._pkgname, 'workon_home': self._workon_home})
|
||||
if os.path.isdir(self._workon_home):
|
||||
for d in sorted(os.listdir(self._workon_home)):
|
||||
if os.path.isdir(os.path.join(self._workon_home, d)):
|
||||
logger.log(d)
|
||||
|
||||
def _write(self, src):
|
||||
fp = open(PATH_ETC_VENV, 'w')
|
||||
fp = open(PATH_HOME_ETC_VENV, 'w')
|
||||
fp.write(src)
|
||||
fp.close()
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ class VersionCommand(Command):
|
||||
summary = "Show version"
|
||||
|
||||
def run_command(self, options, args):
|
||||
logger.info(VERSION)
|
||||
logger.log(VERSION)
|
||||
|
||||
VersionCommand()
|
||||
|
||||
Reference in New Issue
Block a user