From afaa58d024120d556c6289c296a0355a73069309 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 20 Jan 2012 14:34:45 +0100 Subject: [PATCH] Minor name nitpicking and a fix for subcommands. --- AUTHORS.txt | 1 + docs/news.txt | 4 ++++ pip/basecommand.py | 5 +++-- pip/baseparser.py | 12 +++++------- pip/download.py | 11 ++++++----- pip/req.py | 7 ++++--- pip/util.py | 3 ++- pip/vcs/__init__.py | 38 +++++++++++++++++++++++--------------- 8 files changed, 48 insertions(+), 33 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 7eb00388a..c3e44070d 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -31,6 +31,7 @@ Olivier Girardot Patrick Jenkins Paul Nasrat Paul Oswald +Paul van der Linden Peter Waller Qiangning Hong Rene Dudfield diff --git a/docs/news.txt b/docs/news.txt index f6bb63fb0..3c3c3a122 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -48,6 +48,10 @@ develop (unreleased) * Fixed issue #22 - pip search should set and return a userful shell status code +* Fixed issue #351 and #365 - added global ``--exists-action`` command line + option to easier script file exists conflicts, e.g. from editable + requirements from VCS that have a changed repo URL. + 1.0.2 (2011-07-16) ------------------ diff --git a/pip/basecommand.py b/pip/basecommand.py index 5b607cb31..cf50a9e33 100644 --- a/pip/basecommand.py +++ b/pip/basecommand.py @@ -48,8 +48,9 @@ class Command(object): # Make sure we have all global options carried over for attr in ['log', 'proxy', 'require_venv', 'log_explicit_levels', 'log_file', - 'timeout', 'default_vcs', 'skip_requirements_regex', - 'no_input']: + 'timeout', 'default_vcs', + 'skip_requirements_regex', + 'no_input', 'exists_action']: setattr(options, attr, getattr(initial_options, attr) or getattr(options, attr)) options.quiet += initial_options.quiet options.verbose += initial_options.verbose diff --git a/pip/baseparser.py b/pip/baseparser.py index 16d46914a..b3864f3da 100644 --- a/pip/baseparser.py +++ b/pip/baseparser.py @@ -214,15 +214,13 @@ parser.add_option( '--exists-action', dest='exists_action', type='choice', - choices=('s', 'i', 'w', 'b'), + choices=['s', 'i', 'w', 'b'], default=[], action='append', help="Default action when a path already exists." - "Use this option more then one time to specify another action when a certain option is not available, choices: " - "(s)witch," - "(i)gnore," - "(w)ipe," - "(b)ackup" -) + "Use this option more then one time to specify " + "another action if a certain option is not " + "available, choices: " + "(s)witch, (i)gnore, (w)ipe, (b)ackup") parser.disable_interspersed_args() diff --git a/pip/download.py b/pip/download.py index 9fe8a8374..43984a3e2 100644 --- a/pip/download.py +++ b/pip/download.py @@ -9,9 +9,9 @@ import tempfile from pip.backwardcompat import (md5, copytree, xmlrpclib, urllib, urllib2, urlparse, string_types, HTTPError) from pip.exceptions import InstallationError -from pip.util import (splitext, rmtree, - format_size, display_path, backup_dir, ask, path_exists, - unpack_file, create_download_cache_folder, cache_download) +from pip.util import (splitext, rmtree, format_size, display_path, + backup_dir, ask, ask_path_exists, unpack_file, + create_download_cache_folder, cache_download) from pip.vcs import vcs from pip.log import logger @@ -388,8 +388,9 @@ def _copy_file(filename, location, content_type, link): copy = True download_location = os.path.join(location, link.filename) if os.path.exists(download_location): - response = path_exists('The file %s exists. (i)gnore, (w)ipe, (b)ackup ' - % display_path(download_location), ('i', 'w', 'b')) + response = ask_path_exists( + 'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' % + display_path(download_location), ('i', 'w', 'b')) if response == 'i': copy = False elif response == 'w': diff --git a/pip/req.py b/pip/req.py index 3e90c5735..8b7bd06cb 100644 --- a/pip/req.py +++ b/pip/req.py @@ -11,7 +11,7 @@ from pip.exceptions import (InstallationError, UninstallationError, from pip.vcs import vcs from pip.log import logger from pip.util import display_path, rmtree -from pip.util import ask, path_exists, backup_dir +from pip.util import ask, ask_path_exists, backup_dir from pip.util import is_installable_dir, is_local, dist_is_local from pip.util import renames, normalize_path, egg_link_path from pip.util import make_path_relative @@ -506,8 +506,9 @@ exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec')) archive_name = '%s-%s.zip' % (self.name, self.installed_version) archive_path = os.path.join(build_dir, archive_name) if os.path.exists(archive_path): - response = path_exists('The file %s exists. (i)gnore, (w)ipe, (b)ackup ' - % display_path(archive_path), ('i', 'w', 'b')) + response = ask_path_exists( + 'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' % + display_path(archive_path), ('i', 'w', 'b')) if response == 'i': create_archive = False elif response == 'w': diff --git a/pip/util.py b/pip/util.py index 9caf4a402..cec4eba48 100644 --- a/pip/util.py +++ b/pip/util.py @@ -102,7 +102,8 @@ def get_pathext(default_pathext=None): pathext = os.environ.get('PATHEXT', default_pathext) return pathext -def path_exists(message, options): + +def ask_path_exists(message, options): for action in os.environ.get('PIP_EXISTS_ACTION', ''): if action in options: return action diff --git a/pip/vcs/__init__.py b/pip/vcs/__init__.py index f3101bd37..a2137e96a 100644 --- a/pip/vcs/__init__.py +++ b/pip/vcs/__init__.py @@ -5,7 +5,8 @@ import shutil from pip.backwardcompat import urlparse, urllib from pip.log import logger -from pip.util import display_path, backup_dir, find_command, ask, rmtree, path_exists +from pip.util import (display_path, backup_dir, find_command, + ask, rmtree, ask_path_exists) __all__ = ['vcs', 'get_src_requirement'] @@ -182,27 +183,34 @@ class VersionControl(object): if os.path.exists(os.path.join(dest, self.dirname)): existing_url = self.get_url(dest) if self.compare_urls(existing_url, url): - logger.info('%s in %s exists, and has correct URL (%s)' - % (self.repo_name.title(), display_path(dest), url)) - logger.notify('Updating %s %s%s' - % (display_path(dest), self.repo_name, rev_display)) + logger.info('%s in %s exists, and has correct URL (%s)' % + (self.repo_name.title(), display_path(dest), + url)) + logger.notify('Updating %s %s%s' % + (display_path(dest), self.repo_name, + rev_display)) self.update(dest, rev_options) else: - logger.warn('%s %s in %s exists with URL %s' - % (self.name, self.repo_name, display_path(dest), existing_url)) - prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ', ('s', 'i', 'w', 'b')) + logger.warn('%s %s in %s exists with URL %s' % + (self.name, self.repo_name, + display_path(dest), existing_url)) + prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ', + ('s', 'i', 'w', 'b')) else: - logger.warn('Directory %s already exists, and is not a %s %s.' - % (dest, self.name, self.repo_name)) + logger.warn('Directory %s already exists, ' + 'and is not a %s %s.' % + (dest, self.name, self.repo_name)) prompt = ('(i)gnore, (w)ipe, (b)ackup ', ('i', 'w', 'b')) if prompt: - logger.warn('The plan is to install the %s repository %s' - % (self.name, url)) - response = path_exists('What to do? %s' % prompt[0], prompt[1]) + logger.warn('The plan is to install the %s repository %s' % + (self.name, url)) + response = ask_path_exists('What to do? %s' % prompt[0], + prompt[1]) if response == 's': - logger.notify('Switching %s %s to %s%s' - % (self.repo_name, display_path(dest), url, rev_display)) + logger.notify('Switching %s %s to %s%s' % + (self.repo_name, display_path(dest), url, + rev_display)) self.switch(dest, url, rev_options) elif response == 'i': # do nothing