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 Patrick Jenkins
Paul Nasrat Paul Nasrat
Paul Oswald Paul Oswald
Paul van der Linden
Peter Waller Peter Waller
Qiangning Hong Qiangning Hong
Rene Dudfield 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 #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) 1.0.2 (2011-07-16)
------------------ ------------------

View File

@ -48,8 +48,9 @@ class Command(object):
# Make sure we have all global options carried over # Make sure we have all global options carried over
for attr in ['log', 'proxy', 'require_venv', for attr in ['log', 'proxy', 'require_venv',
'log_explicit_levels', 'log_file', 'log_explicit_levels', 'log_file',
'timeout', 'default_vcs', 'skip_requirements_regex', 'timeout', 'default_vcs',
'no_input']: 'skip_requirements_regex',
'no_input', 'exists_action']:
setattr(options, attr, getattr(initial_options, attr) or getattr(options, attr)) setattr(options, attr, getattr(initial_options, attr) or getattr(options, attr))
options.quiet += initial_options.quiet options.quiet += initial_options.quiet
options.verbose += initial_options.verbose options.verbose += initial_options.verbose

View File

@ -214,15 +214,13 @@ parser.add_option(
'--exists-action', '--exists-action',
dest='exists_action', dest='exists_action',
type='choice', type='choice',
choices=('s', 'i', 'w', 'b'), choices=['s', 'i', 'w', 'b'],
default=[], default=[],
action='append', action='append',
help="Default action when a path already exists." 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: " "Use this option more then one time to specify "
"(s)witch," "another action if a certain option is not "
"(i)gnore," "available, choices: "
"(w)ipe," "(s)witch, (i)gnore, (w)ipe, (b)ackup")
"(b)ackup"
)
parser.disable_interspersed_args() parser.disable_interspersed_args()

View File

@ -9,9 +9,9 @@ import tempfile
from pip.backwardcompat import (md5, copytree, xmlrpclib, urllib, urllib2, from pip.backwardcompat import (md5, copytree, xmlrpclib, urllib, urllib2,
urlparse, string_types, HTTPError) urlparse, string_types, HTTPError)
from pip.exceptions import InstallationError from pip.exceptions import InstallationError
from pip.util import (splitext, rmtree, from pip.util import (splitext, rmtree, format_size, display_path,
format_size, display_path, backup_dir, ask, path_exists, backup_dir, ask, ask_path_exists, unpack_file,
unpack_file, create_download_cache_folder, cache_download) create_download_cache_folder, cache_download)
from pip.vcs import vcs from pip.vcs import vcs
from pip.log import logger from pip.log import logger
@ -388,8 +388,9 @@ def _copy_file(filename, location, content_type, link):
copy = True copy = True
download_location = os.path.join(location, link.filename) download_location = os.path.join(location, link.filename)
if os.path.exists(download_location): if os.path.exists(download_location):
response = path_exists('The file %s exists. (i)gnore, (w)ipe, (b)ackup ' response = ask_path_exists(
% display_path(download_location), ('i', 'w', 'b')) 'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' %
display_path(download_location), ('i', 'w', 'b'))
if response == 'i': if response == 'i':
copy = False copy = False
elif response == 'w': elif response == 'w':

View File

@ -11,7 +11,7 @@ from pip.exceptions import (InstallationError, UninstallationError,
from pip.vcs import vcs from pip.vcs import vcs
from pip.log import logger from pip.log import logger
from pip.util import display_path, rmtree 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 is_installable_dir, is_local, dist_is_local
from pip.util import renames, normalize_path, egg_link_path from pip.util import renames, normalize_path, egg_link_path
from pip.util import make_path_relative 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_name = '%s-%s.zip' % (self.name, self.installed_version)
archive_path = os.path.join(build_dir, archive_name) archive_path = os.path.join(build_dir, archive_name)
if os.path.exists(archive_path): if os.path.exists(archive_path):
response = path_exists('The file %s exists. (i)gnore, (w)ipe, (b)ackup ' response = ask_path_exists(
% display_path(archive_path), ('i', 'w', 'b')) 'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' %
display_path(archive_path), ('i', 'w', 'b'))
if response == 'i': if response == 'i':
create_archive = False create_archive = False
elif response == 'w': elif response == 'w':

View File

@ -102,7 +102,8 @@ def get_pathext(default_pathext=None):
pathext = os.environ.get('PATHEXT', default_pathext) pathext = os.environ.get('PATHEXT', default_pathext)
return pathext return pathext
def path_exists(message, options):
def ask_path_exists(message, options):
for action in os.environ.get('PIP_EXISTS_ACTION', ''): for action in os.environ.get('PIP_EXISTS_ACTION', ''):
if action in options: if action in options:
return action return action

View File

@ -5,7 +5,8 @@ import shutil
from pip.backwardcompat import urlparse, urllib from pip.backwardcompat import urlparse, urllib
from pip.log import logger 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'] __all__ = ['vcs', 'get_src_requirement']
@ -182,27 +183,34 @@ class VersionControl(object):
if os.path.exists(os.path.join(dest, self.dirname)): if os.path.exists(os.path.join(dest, self.dirname)):
existing_url = self.get_url(dest) existing_url = self.get_url(dest)
if self.compare_urls(existing_url, url): if self.compare_urls(existing_url, url):
logger.info('%s in %s exists, and has correct URL (%s)' logger.info('%s in %s exists, and has correct URL (%s)' %
% (self.repo_name.title(), display_path(dest), url)) (self.repo_name.title(), display_path(dest),
logger.notify('Updating %s %s%s' url))
% (display_path(dest), self.repo_name, rev_display)) logger.notify('Updating %s %s%s' %
(display_path(dest), self.repo_name,
rev_display))
self.update(dest, rev_options) self.update(dest, rev_options)
else: else:
logger.warn('%s %s in %s exists with URL %s' logger.warn('%s %s in %s exists with URL %s' %
% (self.name, self.repo_name, display_path(dest), existing_url)) (self.name, self.repo_name,
prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ', ('s', 'i', 'w', 'b')) display_path(dest), existing_url))
prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ',
('s', 'i', 'w', 'b'))
else: else:
logger.warn('Directory %s already exists, and is not a %s %s.' logger.warn('Directory %s already exists, '
% (dest, self.name, self.repo_name)) 'and is not a %s %s.' %
(dest, self.name, self.repo_name))
prompt = ('(i)gnore, (w)ipe, (b)ackup ', ('i', 'w', 'b')) prompt = ('(i)gnore, (w)ipe, (b)ackup ', ('i', 'w', 'b'))
if prompt: if prompt:
logger.warn('The plan is to install the %s repository %s' logger.warn('The plan is to install the %s repository %s' %
% (self.name, url)) (self.name, url))
response = path_exists('What to do? %s' % prompt[0], prompt[1]) response = ask_path_exists('What to do? %s' % prompt[0],
prompt[1])
if response == 's': if response == 's':
logger.notify('Switching %s %s to %s%s' logger.notify('Switching %s %s to %s%s' %
% (self.repo_name, display_path(dest), url, rev_display)) (self.repo_name, display_path(dest), url,
rev_display))
self.switch(dest, url, rev_options) self.switch(dest, url, rev_options)
elif response == 'i': elif response == 'i':
# do nothing # do nothing