diff options
author | Tarek Ziade <tarek@ziade.org> | 2011-05-30 21:26:51 (GMT) |
---|---|---|
committer | Tarek Ziade <tarek@ziade.org> | 2011-05-30 21:26:51 (GMT) |
commit | f47fa58b62e6702f840625bff9fc8a07cef3408f (patch) | |
tree | c15db8280b00b1601f884756ec966cb840e91fd5 /Lib/packaging/install.py | |
parent | 58ab76696536b63f588f10eeb165deae6c0e4624 (diff) | |
download | cpython-f47fa58b62e6702f840625bff9fc8a07cef3408f.zip cpython-f47fa58b62e6702f840625bff9fc8a07cef3408f.tar.gz cpython-f47fa58b62e6702f840625bff9fc8a07cef3408f.tar.bz2 |
better UI when the user does not have the perms to remove the project
Diffstat (limited to 'Lib/packaging/install.py')
-rw-r--r-- | Lib/packaging/install.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Lib/packaging/install.py b/Lib/packaging/install.py index cd2bbb6..9f94532 100644 --- a/Lib/packaging/install.py +++ b/Lib/packaging/install.py @@ -376,7 +376,10 @@ def _remove_dist(dist, paths=sys.path): def remove(project_name, paths=sys.path, auto_confirm=True): - """Removes a single project from the installation""" + """Removes a single project from the installation. + + Returns True on success + """ dist = get_distribution(project_name, use_egg_info=True, paths=paths) if dist is None: raise PackagingError('Distribution "%s" not found' % project_name) @@ -384,13 +387,26 @@ def remove(project_name, paths=sys.path, auto_confirm=True): rmdirs = [] rmfiles = [] tmp = tempfile.mkdtemp(prefix=project_name + '-uninstall') + + def _move_file(source, target): + try: + os.rename(source, target) + except OSError as err: + return err + return None + + success = True + error = None try: for file_, md5, size in files: if os.path.isfile(file_): dirname, filename = os.path.split(file_) tmpfile = os.path.join(tmp, filename) try: - os.rename(file_, tmpfile) + error = _move_file(file_, tmpfile) + if error is not None: + success = False + break finally: if not os.path.isfile(file_): os.rename(tmpfile, file_) @@ -401,6 +417,11 @@ def remove(project_name, paths=sys.path, auto_confirm=True): finally: shutil.rmtree(tmp) + if not success: + logger.info('%r cannot be removed.', project_name) + logger.info('Error: %s' % str(error)) + return False + logger.info('Removing %r: ', project_name) for file_ in rmfiles: @@ -447,6 +468,8 @@ def remove(project_name, paths=sys.path, auto_confirm=True): logger.info('Success: removed %d files and %d dirs', file_count, dir_count) + return True + def install(project): logger.info('Getting information about %r...', project) |