diff --git a/README b/README deleted file mode 100644 index 355c04d..0000000 --- a/README +++ /dev/null @@ -1,55 +0,0 @@ -=== USAGE: - pythonbrew [options] [init|install|installed|switch|off|version] - - # Initialize - pythonbrew init - - # Install pythonbrew - pythonbrew install - - # Install some Pythons - pythonbrew install Python-2.6.6 - pythonbrew install Python-2.5.5 - pythonbrew --build-options="CC=gcc_4.1" install Python-2.4.3 - - # Switch python in the $PATH - pythonbrew switch Python-2.6.6 - pythonbrew switch /path/to/Python-2.5.5/ - pythonbrew switch /path/to/python - - # Disable pythonbrew - pythonbrew off - - # Version - pythonbrew version - -=== COMMANDS: - = init - Run this once to setup the pythonbrew directory ready for installing - pythons into. Run it again if you decide to change PYTHONBREW_ROOT. - - = install Python- - Build and install the given version of python. - - = installed - List the installed versions of python. - - = switch Python- - Switch to the given version. - - = switch /path/to/Python-dir/ - Switch to the given version of python in directory. - - = switch /path/to/python - Switch to the given version of python. - - = off - Disable pythonbrew. - - = version - Show version. - -=== OPTIONS: - = --force - = --build-options - \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..fcc516b --- /dev/null +++ b/README.rst @@ -0,0 +1,97 @@ +Overview +======== + +pythonbrew is a program to automate the building and installation of Python in the users HOME. + +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 -LO http://github.com/utahta/pythonbrew/raw/master/pythonbrew + chmod +x pythonbrew + ./pythonbrew install + +After that, pythonbrew installs itself to ~/python/pythonbrew/bin, and you should follow the instruction on screen to setup your .bashrc or .cshrc to put it in your PATH. + +If you need to install pythonbrew into somewhere else, you can do that by setting a PYTHONBREW_ROOT environment variable.:: + + export PYTHONBREW_ROOT=/path/to/pythonbrew + ./pythonbrew install + +Usage +===== + +pythonbrew [options] [init|install|installed|switch|off|version] + +Initialize:: + + pythonbrew init + +Install some Pythons:: + + pythonbrew install Python-2.6.6 + pythonbrew install Python-2.5.5 + pythonbrew --build-options="CC=gcc_4.1" install Python-2.5.4 + pythonbrew --no-setuptools install Python-2.5.3 + +Switch python in the $PATH:: + + pythonbrew switch Python-2.6.6 + pythonbrew switch /path/to/Python-2.5.5/ + pythonbrew switch /path/to/python + +Disable pythonbrew:: + + pythonbrew off + +Version:: + + pythonbrew version + +COMMANDS +======== + +init + Run this once to setup the pythonbrew directory ready for installing + pythons into. Run it again if you decide to change PYTHONBREW_ROOT. + +install Python- + Build and install the given version of Python. + Setuptools is automatically installed. + options: --force, --no-setuptools or --build-options. + +installed + List the installed versions of python. + +switch Python- + Switch to the given version. + +switch /path/to/Python-dir/ + Switch to the given version of python in directory. + +switch /path/to/python + Switch to the given version of python. + +off + Disable pythonbrew. + +version + Show version. + +Options +======= + +--force + Force installation of a Python. + +--build-options + Configure options. + +--no-setuptools + Skip installation of setuptools. diff --git a/pythonbrew b/pythonbrew index c310f63..227ee8e 100755 --- a/pythonbrew +++ b/pythonbrew @@ -10,6 +10,7 @@ import shutil import filecmp import subprocess import getopt +import stat VERSION = "0.1" if os.environ.has_key("PYTHONBREW_ROOT"): @@ -25,7 +26,7 @@ class PythonbrewOptions(object): self._args = sys.argv[1:] self._opts = {} try: - (opts, args) = getopt.getopt(self._args, "hf", ["help", "force", "build-options="]) + (opts, args) = getopt.getopt(self._args, "hf", ["help", "force", "build-options=", "no-setuptools"]) except getopt.GetoptError: self._help() sys.exit() @@ -37,6 +38,8 @@ class PythonbrewOptions(object): self._opts["force"] = True if o in ("--build-options"): self._opts["build-options"] = a; + if o in ("--no-setuptools"): + self._opts["no-setuptools"] = True self._args = args if len(self._args) == 0: self._help() @@ -62,32 +65,13 @@ class PythonbrewOptions(object): else: return "" + def no_setuptools(self): + return self._opts.get("no-setuptools") == True + def _help(self): print """=== USAGE: pythonbrew [options] [init|install|installed|switch|off|version] - # Initialize - pythonbrew init - - # Install pythonbrew - pythonbrew install - - # Install some Pythons - pythonbrew install Python-2.6.6 - pythonbrew install Python-2.5.5 - pythonbrew --build-options="CC=gcc_4.1" install Python-2.4.3 - - # Switch python in the $PATH - pythonbrew switch Python-2.6.6 - pythonbrew switch /path/to/Python-2.5.5/ - pythonbrew switch /path/to/python - - # Disable pythonbrew - pythonbrew off - - # Version - pythonbrew version - === COMMANDS: = init Run this once to setup the pythonbrew directory ready for installing @@ -95,6 +79,7 @@ class PythonbrewOptions(object): = install Python- Build and install the given version of python. + options: --force, --no-setuptools or --build-options. = installed List the installed versions of python. @@ -116,7 +101,16 @@ class PythonbrewOptions(object): === OPTIONS: = --force + Force installation of a Python. + = --build-options + Configure options. + + = --no-setuptools + setuptools is not installed. + +=== FURTHER INSTRUCTIONS + http://github.com/utahta/pythonbrew """ class Pythonbrew(object): @@ -214,7 +208,7 @@ And follow the instruction on screen.""" dist_version = m.group(1) dist_tarball = "%s.tgz" % dist - sys.stdout.write("%s..." % dist_tarball) + sys.stdout.write("Downloading %s..." % dist_tarball) sys.stdout.flush() urllib.urlretrieve( PYTHONDLSITE % (dist_version, dist_tarball), "%s/dists/%s" % (ROOT, dist_tarball), @@ -250,16 +244,34 @@ And follow the instruction on screen.""" pythonbrew --force install """+dist sys.exit() + # install ez_setup + self._install_ez_setup( dist ) print """Installed """+dist+""" successfully. Run the following command to switch to it. pythonbrew switch """+dist + def _install_ez_setup(self, pydist): + if self._options.no_setuptools(): + print "Skip installation setuptools." + return + dist = EZSETUPDLSITE + dist = dist[dist.rfind("/")+1:] + + urllib.urlretrieve( EZSETUPDLSITE, + "%s/dists/%s" % (ROOT, dist), + self._download_progress ) + os.system( "%s/pythons/%s/bin/python %s/dists/%s" % (ROOT, pydist, ROOT, dist) ) + if os.path.isfile("%s/pythons/%s/bin/easy_install" % (ROOT, pydist)): + os.system( "%s/pythons/%s/bin/easy_install pip" % (ROOT, pydist) ) + def run_command_installed(self): - if os.path.realpath( "%s/pythons/current" % ROOT ) == ROOT: - cur = os.path.realpath("%s/bin/python" % ROOT) - else: - cur = os.path.realpath( "%s/pythons/current" % ROOT ) - print "%s (*)" % cur + cur = "" + if os.path.islink( "%s/pythons/current" % ROOT ): + if os.path.realpath( "%s/pythons/current" % ROOT ) == ROOT: + cur = os.path.realpath("%s/bin/python" % ROOT) + else: + cur = os.path.realpath( "%s/pythons/current" % ROOT ) + print "%s (*)" % cur for d in os.listdir("%s/pythons/" % ROOT): if d == "current" or cur == "%s/pythons/%s" % (ROOT,d):