From 8e54618ff4403acb44627d8da44d7df2fcbb3e9c Mon Sep 17 00:00:00 2001 From: utahta Date: Thu, 25 Nov 2010 23:14:19 +0900 Subject: [PATCH] removed installed command. added some functions to bashrc. --- PKG-INFO | 3 -- README.rst | 3 -- pythonbrew/commands/installed.py | 24 ---------------- pythonbrew/installer.py | 4 ++- pythonbrew/scripts/bashrc | 47 +++++++++++++++++++++----------- pythonbrew/util.py | 2 +- 6 files changed, 35 insertions(+), 48 deletions(-) delete mode 100644 pythonbrew/commands/installed.py diff --git a/PKG-INFO b/PKG-INFO index 453420f..d05f7db 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -8,9 +8,6 @@ pythonbrew is based on `perlbrew `_. Installation ============ -Following python version is required to use pythonbrew: - 2.4 <= Python < 3 - The recommended way to download and install pythonbrew is to run these statements in your shell.:: easy_install pythonbrew diff --git a/README.rst b/README.rst index 04c1b7d..b4a8131 100644 --- a/README.rst +++ b/README.rst @@ -8,9 +8,6 @@ pythonbrew is based on `perlbrew `_. Installation ============ -Following python version is required to use pythonbrew: - 2.4 <= Python < 3 - The recommended way to download and install pythonbrew is to run these statements in your shell.:: curl -kL http://github.com/utahta/pythonbrew/raw/master/pythonbrew-install | bash diff --git a/pythonbrew/commands/installed.py b/pythonbrew/commands/installed.py deleted file mode 100644 index 2524f13..0000000 --- a/pythonbrew/commands/installed.py +++ /dev/null @@ -1,24 +0,0 @@ -import os -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" - usage = "%prog" - summary = "List the installed versions of python" - - def run_command(self, options, args): - 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(d) - if cur: - logger.info('%s (*)' % cur) - -InstalledCommand() diff --git a/pythonbrew/installer.py b/pythonbrew/installer.py index 4277c03..427e666 100644 --- a/pythonbrew/installer.py +++ b/pythonbrew/installer.py @@ -63,10 +63,12 @@ class PythonbrewInstaller(object): makedirs(PATH_ETC) makedirs(PATH_BIN) makedirs(PATH_LOG) + + rm_r(PATH_SCRIPTS) makedirs(PATH_SCRIPTS) makedirs(PATH_SCRIPTS_PYTHONBREW) makedirs(PATH_SCRIPTS_PYTHONBREW_COMMANDS) - + for path in glob.glob(os.path.join(installer_root,"*.py")): shutil.copy(path, PATH_SCRIPTS_PYTHONBREW) diff --git a/pythonbrew/scripts/bashrc b/pythonbrew/scripts/bashrc index e4adb61..c6d9096 100644 --- a/pythonbrew/scripts/bashrc +++ b/pythonbrew/scripts/bashrc @@ -1,21 +1,21 @@ -PYTHONBREW_ROOT="@ROOT@" -PYTHONBREW_ETC="$PYTHONBREW_ROOT/etc" +PATH_ROOT="@ROOT@" +PATH_ETC="$PATH_ROOT/etc" __pythonbrew_set_default() { - PATH_PYTHONBREW="$PYTHONBREW_ROOT/bin" + PATH_PYTHONBREW="$PATH_ROOT/bin" } __pythonbrew_set_path() { - PATH_WITHOUT_PYTHONBREW=$(printf $PATH | awk -v RS=: -v ORS=: "/${PYTHONBREW_ROOT//\//\/}/ {next} {print}" | sed -e 's#:$##') + PATH_WITHOUT_PYTHONBREW=$(printf $PATH | awk -v RS=: -v ORS=: "/${PATH_ROOT//\//\/}/ {next} {print}" | sed -e 's#:$##') export PATH=$PATH_PYTHONBREW:$PATH_WITHOUT_PYTHONBREW } __pythonbrew_set_temp_path() { - if [[ -s "$PYTHONBREW_ETC/temp" ]] ; then - source "$PYTHONBREW_ETC/temp" + if [[ -s "$PATH_ETC/temp" ]] ; then + source "$PATH_ETC/temp" else __pythonbrew_set_default fi @@ -24,8 +24,8 @@ __pythonbrew_set_temp_path() __pythonbrew_set_current_path() { - if [[ -s "$PYTHONBREW_ETC/current" ]] ; then - source "$PYTHONBREW_ETC/current" + if [[ -s "$PATH_ETC/current" ]] ; then + source "$PATH_ETC/current" else __pythonbrew_set_default fi @@ -34,38 +34,52 @@ __pythonbrew_set_current_path() __pythonbrew_reload() { - if [[ -s "$PYTHONBREW_ETC/bashrc" ]] ; then - source "$PYTHONBREW_ETC/bashrc" - fi + [[ -s "$PATH_ETC/bashrc" ]] && source "$PATH_ETC/bashrc" } __pythonbrew_use() { command pythonbrew "$@" - __pythonbrew_set_temp_path + [[ $? == 0 ]] && __pythonbrew_set_temp_path } __pythonbrew_switch() { command pythonbrew "$@" - __pythonbrew_set_current_path + [[ $? == 0 ]] && __pythonbrew_set_current_path } __pythonbrew_off() { command pythonbrew "$@" - __pythonbrew_set_current_path + [[ $? == 0 ]] && __pythonbrew_set_current_path } __pythonbrew_update() { command pythonbrew "$@" - __pythonbrew_reload + [[ $? == 0 ]] && __pythonbrew_reload +} + +__pythonbrew_find_command() +{ + command_name="" + for arg in "$@" ; do + case $arg in + --*) continue;; + -*) continue;; + *) + command_name=$arg + break + ;; + esac + done } pythonbrew() { - case $1 in + __pythonbrew_find_command "$@" + case $command_name in use) __pythonbrew_use "$@";; switch) __pythonbrew_switch "$@" ;; off) __pythonbrew_off "$@" ;; @@ -77,3 +91,4 @@ pythonbrew() # main __pythonbrew_set_current_path + diff --git a/pythonbrew/util.py b/pythonbrew/util.py index 0ccda5b..c70a831 100644 --- a/pythonbrew/util.py +++ b/pythonbrew/util.py @@ -6,11 +6,11 @@ import re import posixpath import tarfile import platform +from subprocess import PIPE, Popen from pythonbrew.define import PATH_BIN, PATH_PYTHONS, PATH_ETC_CURRENT,\ PATH_ETC_TEMP from pythonbrew.exceptions import ShellCommandException from pythonbrew.log import logger -from subprocess import PIPE, Popen def size_format(b): kb = 1000