Minor name nitpicking and a fix for subcommands.

This commit is contained in:
Jannis Leidel 2012-01-20 14:34:45 +01:00
parent b77a7c4f5f
commit afaa58d024
8 changed files with 48 additions and 33 deletions

View File

@ -31,6 +31,7 @@ Olivier Girardot
Patrick Jenkins
Paul Nasrat
Paul Oswald
Paul van der Linden
Peter Waller
Qiangning Hong
Rene Dudfield

View File

@ -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)
------------------

View File

@ -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

View File

@ -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()

View File

@ -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':

View File

@ -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':

View File

@ -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

View File

@ -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