mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
update
This commit is contained in:
@@ -3,7 +3,7 @@ import sys
|
||||
import subprocess
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE, PATH_DISTS
|
||||
from pythonbrew.util import Package, get_current_python_path, Link
|
||||
from pythonbrew.util import Package, get_current_use_pkgname, Link, is_installed
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader
|
||||
|
||||
@@ -21,18 +21,19 @@ class BuildoutCommand(Command):
|
||||
help="Use the specified version of python.",
|
||||
metavar='VERSION'
|
||||
)
|
||||
self.parser.disable_interspersed_args()
|
||||
|
||||
def run_command(self, options, args):
|
||||
if options.python:
|
||||
python = Package(options.python).name
|
||||
python = os.path.join(PATH_PYTHONS, python, 'bin', 'python')
|
||||
if not os.path.isfile(python):
|
||||
logger.info('%s is not installed.' % options.python)
|
||||
sys.exit(1)
|
||||
pkgname = Package(options.python).name
|
||||
else:
|
||||
python = get_current_python_path()
|
||||
logger.info('Using %s' % python)
|
||||
pkgname = get_current_use_pkgname()
|
||||
if not is_installed(pkgname):
|
||||
logger.info('%s is not installed.' % pkgname)
|
||||
sys.exit(1)
|
||||
logger.info('Using %s' % pkgname)
|
||||
|
||||
# build a path
|
||||
python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
|
||||
|
||||
# Download bootstrap.py
|
||||
download_url = BOOTSTRAP_DLSITE
|
||||
|
||||
@@ -3,7 +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_current_python_path
|
||||
from pythonbrew.util import Package, get_current_use_pkgname
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class ListCommand(Command):
|
||||
@@ -36,9 +36,9 @@ class ListCommand(Command):
|
||||
|
||||
def installed(self, options, args):
|
||||
logger.info('# installed pythons')
|
||||
cur = get_current_python_path()
|
||||
cur = get_current_use_pkgname()
|
||||
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||
if cur and os.path.samefile(cur, os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
||||
if cur and cur == d:
|
||||
logger.info('%s (*)' % d)
|
||||
cur = None
|
||||
else:
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import Package, set_current_path
|
||||
from pythonbrew.util import Package, set_current_path, is_installed
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class SwitchCommand(Command):
|
||||
@@ -16,11 +16,10 @@ class SwitchCommand(Command):
|
||||
sys.exit(1)
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgdir):
|
||||
if not is_installed(pkgname):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
pkgbin = os.path.join(pkgdir,'bin')
|
||||
pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
|
||||
|
||||
set_current_path('%s:%s' % (PATH_BIN, pkgbin))
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import os
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import off, rm_r, Package, get_current_python_path, unlink
|
||||
from pythonbrew.util import off, rm_r, Package, get_current_use_pkgname, unlink,\
|
||||
is_installed
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class UninstallCommand(Command):
|
||||
@@ -16,10 +17,10 @@ class UninstallCommand(Command):
|
||||
pkg = Package(arg)
|
||||
pkgname = pkg.name
|
||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgpath):
|
||||
if not is_installed(pkgname):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
continue
|
||||
if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
|
||||
if get_current_use_pkgname() == pkgname:
|
||||
off()
|
||||
for d in os.listdir(PATH_BIN):
|
||||
# remove symlink
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE, PATH_DISTS
|
||||
from pythonbrew.util import Package, get_current_use_pkgname, Link
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader
|
||||
|
||||
class VenvCommand(Command):
|
||||
name = "venv"
|
||||
usage = "%prog [create|use|delete|list] [project]"
|
||||
summary = "Create isolated python environments"
|
||||
|
||||
def __init__(self):
|
||||
super(VenvCommand, self).__init__()
|
||||
self.parser.add_option(
|
||||
"-p", "--python",
|
||||
dest="python",
|
||||
default=None,
|
||||
help="Use the specified version of python.",
|
||||
metavar='VERSION'
|
||||
)
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.error('Unrecognized command line argument: argument not found.')
|
||||
sys.exit(1)
|
||||
cmd = args[0]
|
||||
if not cmd in ('create', 'use', 'delete', 'list'):
|
||||
logger.error('%s command not found.' % cmd)
|
||||
sys.exit(1)
|
||||
|
||||
# Decide which version of python to use.
|
||||
if options.python:
|
||||
pkgname = Package(options.python).name
|
||||
else:
|
||||
pkgname = get_current_use_pkgname()
|
||||
logger.info('Using %s' % pkgname)
|
||||
|
||||
if cmd == 'create':
|
||||
self._create(args[1:])
|
||||
elif cmd == 'use':
|
||||
self._use(args[1])
|
||||
elif cmd == 'delete':
|
||||
self._delete(args[1:])
|
||||
elif cmd == 'list':
|
||||
self._list()
|
||||
|
||||
# Download bootstrap.py
|
||||
# download_url = BOOTSTRAP_DLSITE
|
||||
# filename = Link(download_url).filename
|
||||
# bootstrap = os.path.join(PATH_DISTS, filename)
|
||||
# try:
|
||||
# d = Downloader()
|
||||
# d.download(filename, download_url, bootstrap)
|
||||
# except:
|
||||
# logger.error("Failed to download. `%s`" % download_url)
|
||||
# sys.exit(1)
|
||||
#
|
||||
# # Using bootstrap.py
|
||||
# if subprocess.call([python, bootstrap, '-d']):
|
||||
# logger.error('Failed to bootstrap.')
|
||||
# sys.exit(1)
|
||||
#
|
||||
# # Using buildout
|
||||
# subprocess.call(['./bin/buildout'])
|
||||
|
||||
def _create(self, projects):
|
||||
"""Create python environment"""
|
||||
for proj in projects:
|
||||
print proj
|
||||
|
||||
def _use(self, project):
|
||||
print project
|
||||
|
||||
def _delete(self, projects):
|
||||
for proj in projects:
|
||||
print proj
|
||||
|
||||
def _list(self):
|
||||
print 'list'
|
||||
|
||||
VenvCommand()
|
||||
Reference in New Issue
Block a user