mirror of https://github.com/pypa/pip
path exists action
This commit is contained in:
parent
ac94f606c0
commit
8d67101b6e
|
@ -75,6 +75,9 @@ class Command(object):
|
|||
|
||||
if options.no_input:
|
||||
os.environ['PIP_NO_INPUT'] = '1'
|
||||
|
||||
if options.exists_action:
|
||||
os.environ['PIP_EXISTS_ACTION'] = ''.join(options.exists_action)
|
||||
|
||||
if options.require_venv:
|
||||
# If a venv is required check if it can really be found
|
||||
|
|
|
@ -200,4 +200,20 @@ parser.add_option(
|
|||
default='',
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
|
||||
parser.add_option(
|
||||
# Option when path already exist
|
||||
'--exists-action',
|
||||
dest='exists_action',
|
||||
type='choice',
|
||||
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"
|
||||
)
|
||||
|
||||
parser.disable_interspersed_args()
|
||||
|
|
|
@ -10,7 +10,7 @@ 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,
|
||||
format_size, display_path, backup_dir, ask, path_exists,
|
||||
unpack_file, create_download_cache_folder, cache_download)
|
||||
from pip.vcs import vcs
|
||||
from pip.log import logger
|
||||
|
@ -388,7 +388,7 @@ 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 = ask('The file %s exists. (i)gnore, (w)ipe, (b)ackup '
|
||||
response = path_exists('The file %s exists. (i)gnore, (w)ipe, (b)ackup '
|
||||
% display_path(download_location), ('i', 'w', 'b'))
|
||||
if response == 'i':
|
||||
copy = False
|
||||
|
|
|
@ -10,7 +10,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, backup_dir
|
||||
from pip.util import 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
|
||||
|
@ -502,7 +502,7 @@ 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 = ask('The file %s exists. (i)gnore, (w)ipe, (b)ackup '
|
||||
response = 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
|
||||
|
|
|
@ -102,6 +102,11 @@ def get_pathext(default_pathext=None):
|
|||
pathext = os.environ.get('PATHEXT', default_pathext)
|
||||
return pathext
|
||||
|
||||
def path_exists(message, options):
|
||||
for action in os.environ.get('PIP_EXISTS_ACTION', ''):
|
||||
if action in options:
|
||||
return action
|
||||
return ask(message, options)
|
||||
|
||||
def ask(message, options):
|
||||
"""Ask the message interactively, with the given possible responses"""
|
||||
|
|
|
@ -5,7 +5,7 @@ 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
|
||||
from pip.util import display_path, backup_dir, find_command, ask, rmtree, path_exists
|
||||
|
||||
|
||||
__all__ = ['vcs', 'get_src_requirement']
|
||||
|
@ -198,7 +198,7 @@ class VersionControl(object):
|
|||
if prompt:
|
||||
logger.warn('The plan is to install the %s repository %s'
|
||||
% (self.name, url))
|
||||
response = ask('What to do? %s' % prompt[0], prompt[1])
|
||||
response = path_exists('What to do? %s' % prompt[0], prompt[1])
|
||||
|
||||
if response == 's':
|
||||
logger.notify('Switching %s %s to %s%s'
|
||||
|
|
Loading…
Reference in New Issue