mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
added use command. added some functions to bashrc.
This commit is contained in:
@@ -14,6 +14,6 @@ class CleanCommand(Command):
|
||||
|
||||
def _clean(self, root):
|
||||
for dir in os.listdir(root):
|
||||
rm_r("%s/%s" % (root, dir))
|
||||
rm_r(os.path.join(root, dir))
|
||||
|
||||
CleanCommand()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
from subprocess import Popen, PIPE
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.util import get_current_python_path
|
||||
|
||||
class InstalledCommand(Command):
|
||||
name = "installed"
|
||||
@@ -11,20 +11,14 @@ class InstalledCommand(Command):
|
||||
summary = "List the installed versions of python"
|
||||
|
||||
def run_command(self, options, args):
|
||||
cur = None
|
||||
if not os.path.islink("%s/current" % PATH_PYTHONS):
|
||||
p = Popen('command -v python', stdout=PIPE, shell=True)
|
||||
p.wait()
|
||||
if p.returncode == 0:
|
||||
logger.info("%s (*)" % p.stdout.read().strip())
|
||||
elif os.path.islink("%s/current" % PATH_PYTHONS):
|
||||
cur = os.path.basename(os.path.realpath("%s/current" % PATH_PYTHONS))
|
||||
for d in sorted(os.listdir("%s/" % PATH_PYTHONS)):
|
||||
if d == "current":
|
||||
continue
|
||||
if cur == d:
|
||||
logger.info("%s (*)" % cur)
|
||||
cur = get_current_python_path()
|
||||
for d in sorted(os.listdir('%s/' % PATH_PYTHONS)):
|
||||
if cur == os.path.join(PATH_PYTHONS, d, 'bin','python'):
|
||||
logger.info('%s (*)' % d)
|
||||
cur = None
|
||||
else:
|
||||
logger.info("%s" % (d))
|
||||
|
||||
logger.info(d)
|
||||
if cur:
|
||||
logger.info('%s (*)' % cur)
|
||||
|
||||
InstalledCommand()
|
||||
|
||||
@@ -1,25 +1,53 @@
|
||||
import os
|
||||
import re
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON
|
||||
from pythonbrew.util import Package
|
||||
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\
|
||||
PATH_PYTHONS
|
||||
from pythonbrew.util import Package, get_current_python_path
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class ListCommand(Command):
|
||||
name = "list"
|
||||
usage = "%prog [VERSION]"
|
||||
summary = "List the available install version of python"
|
||||
|
||||
summary = "List the installed versions of Python"
|
||||
|
||||
def __init__(self):
|
||||
super(ListCommand, self).__init__()
|
||||
self.parser.add_option(
|
||||
"--all-versions",
|
||||
dest="all_versions",
|
||||
action="store_true",
|
||||
'-a', '--all-versions',
|
||||
dest='all_versions',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="All versions of Python are visible."
|
||||
help='All versions of Python are visible'
|
||||
)
|
||||
self.parser.add_option(
|
||||
'-k', '--known',
|
||||
dest='known',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='List the available install versions of Python'
|
||||
)
|
||||
|
||||
def run_command(self, options, args):
|
||||
if options.known:
|
||||
self.available_install(options, args)
|
||||
else:
|
||||
self.installed(options, args)
|
||||
|
||||
def installed(self, options, args):
|
||||
logger.info('# installed pythons')
|
||||
cur = get_current_python_path()
|
||||
for d in sorted(os.listdir('%s/' % PATH_PYTHONS)):
|
||||
if cur == os.path.join(PATH_PYTHONS, d, 'bin','python'):
|
||||
logger.info('%s (*)' % d)
|
||||
cur = None
|
||||
else:
|
||||
logger.info('%s' % d)
|
||||
if cur:
|
||||
logger.info('%s (*)' % cur)
|
||||
|
||||
def available_install(self, options, args):
|
||||
logger.info('# available install pythons')
|
||||
if args:
|
||||
pkg = Package(args[0])
|
||||
_re = re.compile(r"%s" % pkg.name)
|
||||
@@ -31,7 +59,7 @@ class ListCommand(Command):
|
||||
for pkgname in pkgs:
|
||||
logger.info("%s" % pkgname)
|
||||
else:
|
||||
print "Python version not found. `%s`" % pkg.name
|
||||
logger.info("Python version not found. `%s`" % pkg.name)
|
||||
else:
|
||||
for pkgname in self._get_packages_name(options):
|
||||
logger.info("%s" % pkgname)
|
||||
|
||||
@@ -2,13 +2,13 @@ import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import off, symlink, Package
|
||||
from pythonbrew.util import Package, write_current
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class SwitchCommand(Command):
|
||||
name = "switch"
|
||||
usage = "%prog VERSION"
|
||||
summary = "Switch to the given version"
|
||||
summary = "Switch to the given version of python"
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
@@ -20,19 +20,10 @@ class SwitchCommand(Command):
|
||||
if not os.path.isdir(pkgdir):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
self._switch_dir(pkgdir)
|
||||
logger.info("Switched to %s" % pkgname)
|
||||
|
||||
def _switch_dir(self, pkgdir):
|
||||
off()
|
||||
symlink(pkgdir, "%s/current" % PATH_PYTHONS)
|
||||
pkgbin = os.path.join(pkgdir,'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"))
|
||||
write_current('%s:%s' % (PATH_BIN, pkgbin))
|
||||
|
||||
logger.info("Switched to %s" % pkgname)
|
||||
|
||||
SwitchCommand()
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS
|
||||
from pythonbrew.util import off, rm_r, Package
|
||||
from pythonbrew.util import off, rm_r, Package, get_current_python_path
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class UninstallCommand(Command):
|
||||
@@ -14,14 +14,12 @@ class UninstallCommand(Command):
|
||||
if args:
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
pkgpath = "%s/%s" % (PATH_PYTHONS, pkgname)
|
||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgpath):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
if os.path.islink("%s/current" % PATH_PYTHONS):
|
||||
curpath = os.path.realpath("%s/current" % PATH_PYTHONS)
|
||||
if pkgpath == curpath:
|
||||
off()
|
||||
if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
|
||||
off()
|
||||
rm_r(pkgpath)
|
||||
else:
|
||||
self.parser.print_help()
|
||||
|
||||
@@ -55,7 +55,6 @@ class UpdateCommand(Command):
|
||||
s.check_call('%s %s/pythonbrew_install.py --upgrade' % (sys.executable, extract_dir))
|
||||
except:
|
||||
logger.error("Failed to update pythonbrew.")
|
||||
raise
|
||||
sys.exit(1)
|
||||
logger.info("The pythonbrew has been updated.")
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||
from pythonbrew.util import Package, write_temp
|
||||
from pythonbrew.log import logger
|
||||
|
||||
class UseCommand(Command):
|
||||
name = "use"
|
||||
usage = "%prog VERSION"
|
||||
summary = "Using the given version of python"
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
logger.info("Unrecognized command line argument: argument not found.")
|
||||
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)
|
||||
sys.exit(1)
|
||||
pkgbin = os.path.join(pkgdir,'bin')
|
||||
|
||||
write_temp('%s:%s' % (PATH_BIN, pkgbin))
|
||||
|
||||
logger.info("Using `%s`" % pkgname)
|
||||
|
||||
UseCommand()
|
||||
Reference in New Issue
Block a user