From bc219fcebe9fd2eecde8e4257bba844c21d4a24a Mon Sep 17 00:00:00 2001 From: utahta Date: Sun, 7 Aug 2011 12:58:54 +0900 Subject: [PATCH] bug fix --- pythonbrew/__init__.py | 12 ++++++++---- pythonbrew/commands/buildout.py | 7 ++++--- pythonbrew/commands/list.py | 2 +- pythonbrew/commands/symlink.py | 4 ++-- pythonbrew/commands/update.py | 2 +- pythonbrew/commands/venv.py | 2 +- pythonbrew/curl.py | 7 ++++--- pythonbrew/etc/bashrc | 2 +- pythonbrew/exceptions.py | 4 +++- pythonbrew/installer/pythoninstaller.py | 4 ++-- pythonbrew/util.py | 7 +++++++ 11 files changed, 34 insertions(+), 19 deletions(-) diff --git a/pythonbrew/__init__.py b/pythonbrew/__init__.py index d190d8c..9eec705 100644 --- a/pythonbrew/__init__.py +++ b/pythonbrew/__init__.py @@ -1,7 +1,14 @@ import sys +import os from pythonbrew.basecommand import command_dict, load_all_commands from pythonbrew.baseparser import parser from pythonbrew.log import logger +from pythonbrew.define import PATH_HOME_ETC +from pythonbrew.util import makedirs + +def init_home(): + if not os.path.isdir(PATH_HOME_ETC): + makedirs(PATH_HOME_ETC) def main(): options, args = parser.parse_args(sys.argv[1:]) @@ -10,13 +17,10 @@ def main(): if not args: args = ['help'] # as default + init_home() load_all_commands() command = args[0].lower() if command not in command_dict: - if command == 'clean': - # note: for some time - logger.log('\nDEPRECATION WARNING: `pythonbrew clean` has been renamed. Please run `pythonbrew cleanup` instead.\n') - return parser.error("Unknown command: `%s`" % command) return command = command_dict[command] diff --git a/pythonbrew/commands/buildout.py b/pythonbrew/commands/buildout.py index 5d08ffe..1c29574 100644 --- a/pythonbrew/commands/buildout.py +++ b/pythonbrew/commands/buildout.py @@ -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 @@ -38,12 +38,13 @@ 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) # call bootstrap.py diff --git a/pythonbrew/commands/list.py b/pythonbrew/commands/list.py index ab4293d..91dfa6f 100644 --- a/pythonbrew/commands/list.py +++ b/pythonbrew/commands/list.py @@ -56,7 +56,7 @@ class ListCommand(Command): for pkgname in pkgs: logger.log("%s" % pkgname) else: - logger.error("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.log("%s" % pkgname) diff --git a/pythonbrew/commands/symlink.py b/pythonbrew/commands/symlink.py index 54d19c6..f87da05 100644 --- a/pythonbrew/commands/symlink.py +++ b/pythonbrew/commands/symlink.py @@ -63,7 +63,7 @@ class SymlinkCommand(Command): 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 not found in %s." % (options.venv, venv_pkgdir)) + logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir)) sys.exit(1) pkg = Package(pkgname) if args: @@ -105,7 +105,7 @@ class SymlinkCommand(Command): if os.path.isfile(src): symlink(src, dst) else: - logger.error("%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. diff --git a/pythonbrew/commands/update.py b/pythonbrew/commands/update.py index b49d27d..6a3e4a4 100644 --- a/pythonbrew/commands/update.py +++ b/pythonbrew/commands/update.py @@ -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'] diff --git a/pythonbrew/commands/venv.py b/pythonbrew/commands/venv.py index bd8e32e..f01664e 100644 --- a/pythonbrew/commands/venv.py +++ b/pythonbrew/commands/venv.py @@ -83,7 +83,7 @@ class VenvCommand(Command): logger.info('venv command is already initialized.') return if not os.access(PATH_DISTS, os.W_OK): - logger.error("Can not write to %s: Permission denied." % PATH_DISTS) + logger.error("Can not initialize venv command: Permission denied.") sys.exit(1) d = Downloader() download_file = os.path.join(PATH_DISTS, 'virtualenv.tar.gz') diff --git a/pythonbrew/curl.py b/pythonbrew/curl.py index 14b05c3..00e5790 100644 --- a/pythonbrew/curl.py +++ b/pythonbrew/curl.py @@ -4,6 +4,7 @@ import subprocess from subprocess import Popen, PIPE from pythonbrew.log import logger from pythonbrew.util import to_str +from pythonbrew.exceptions import CurlFetchException class Curl(object): def __init__(self): @@ -16,14 +17,14 @@ class Curl(object): p = Popen("curl -skL %s" % url, stdout=PIPE, shell=True) p.wait() if p.returncode: - raise + raise Exception('Failed to read.') return p.stdout.read() def readheader(self, url): p = Popen("curl --head -skL %s" % url, stdout=PIPE, shell=True) p.wait() if p.returncode: - raise + raise Exception('Failed to readheader.') respinfo = {} for line in p.stdout: line = to_str(line.strip()) @@ -39,4 +40,4 @@ class Curl(object): p = Popen("curl -# -kL %s -o %s" % (url, filename), shell=True) p.wait() if p.returncode: - raise + raise CurlFetchException('Failed to fetch.') diff --git a/pythonbrew/etc/bashrc b/pythonbrew/etc/bashrc index da65b41..8944e1e 100644 --- a/pythonbrew/etc/bashrc +++ b/pythonbrew/etc/bashrc @@ -130,7 +130,7 @@ pybrew() sudopybrew() { - pythonbrew="sudo PYTHONBREW_ROOT=$PATH_ROOT $PY_PYTHONBREW" + pythonbrew="sudo PYTHONBREW_ROOT=$PATH_ROOT PATH=$PATH_PYTHONBREW:$PATH_WITHOUT_PYTHONBREW $PY_PYTHONBREW" __pythonbrew_run "$@" } diff --git a/pythonbrew/exceptions.py b/pythonbrew/exceptions.py index fd6cee9..69036f1 100644 --- a/pythonbrew/exceptions.py +++ b/pythonbrew/exceptions.py @@ -11,4 +11,6 @@ class AlreadyInstalledException(Exception): """General exception during installing""" class NotSupportedVersionException(Exception): """General exception during installing""" - \ No newline at end of file + +class CurlFetchException(Exception): + """Exception curl during fetching""" diff --git a/pythonbrew/installer/pythoninstaller.py b/pythonbrew/installer/pythoninstaller.py index fbe89e8..46f8182 100644 --- a/pythonbrew/installer/pythoninstaller.py +++ b/pythonbrew/installer/pythoninstaller.py @@ -107,7 +107,7 @@ class PythonInstaller(object): dl.download(base_url, self.download_url, self.download_file) except: unlink(self.download_file) - logger.log("\nInterrupt to abort. `%s`" % (self.download_url)) + logger.error("\n%s" % (sys.exc_info()[1])) sys.exit(1) # extracting if not extract_downloadfile(self.content_type, self.download_file, self.build_dir): @@ -154,7 +154,7 @@ class PythonInstaller(object): else: s.shell("patch -p0 < %s" % patch) except: - logger.error("Failed to patch `%s`" % self.build_dir) + logger.error("Failed to patch `%s`.\n%s" % (self.build_dir, sys.exc_info()[1])) sys.exit(1) def _add_patches_to_list(self, patch_dir, patch_files): diff --git a/pythonbrew/util.py b/pythonbrew/util.py index 11f6e3d..61b42f1 100644 --- a/pythonbrew/util.py +++ b/pythonbrew/util.py @@ -271,6 +271,11 @@ def is_str(val): return isinstance(val, str) return False +def is_sequence(val): + if is_str(val): + return False + return (hasattr(val, "__getitem__") or hasattr(val, "__iter__")) + def bltin_any(iter): try: return any(iter) @@ -294,6 +299,8 @@ class Subprocess(object): def shell(self, cmd): if self._debug: logger.log(cmd) + if is_sequence(cmd): + cmd = ''.join(cmd) if self._log: if self._verbose: cmd = "(%s) 2>&1 | tee '%s'" % (cmd, self._log)