Refactor output compression into a separate method.
@@ -175,30 +175,18 @@ class UninstallPathSet(object):
logger.info('Successfully uninstalled %s', dist_name_version)
- def _allowed_to_proceed(self, verbose):
- """Display which files would be deleted and prompt for confirmation
- """
+ def compressed_output_listing(self, paths):
+ """Returns a tuple of 2 sets of which paths to display to user
- def _display(msg, paths):
- if not paths:
- return
-
- logger.info(msg)
- with indent_log():
- for path in sorted(self.compact(paths)):
- logger.info(path)
+ Only the folders that have packages inside them and files that are not
+ within those folders. Any files in above folders that would not be
+ deleted would be displayed in a separate skipped list.
+ """
- # In verbose mode, display all the files that are going to be deleted.
- will_remove = list(self.paths)
+ will_remove = list(paths)
will_skip = set()
- if not verbose:
- # In non-verbose mode...
- # Display only the folders that have packages inside them and files
- # that are not within those folders. Any files in above folders
- # that would not be deleted would be displayed in a separate
- # skipped list.
-
+ # Determine folders and files
folders = set()
files = set()
for path in will_remove:
@@ -218,15 +206,38 @@ class UninstallPathSet(object):
if fname.endswith(".pyc"):
continue
- fname = os.path.join(dirpath, fname)
- if os.path.isfile(fname) and fname not in files:
+ file_ = os.path.join(dirpath, fname)
+ if os.path.isfile(file_) and file_ not in files:
# We are skipping this file. Add it to the set.
- will_skip.add(fname)
+ will_skip.add(file_)
will_remove = files | {
os.path.join(folder, "*") for folder in folders
}
+ return will_remove, will_skip
+
+ def _allowed_to_proceed(self, verbose):
+ """Display which files would be deleted and prompt for confirmation
+ """
+
+ def _display(msg, paths):
+ if not paths:
+ return
+
+ logger.info(msg)
+ with indent_log():
+ for path in sorted(self.compact(paths)):
+ logger.info(path)
+
+ if not verbose:
+ will_remove, will_skip = self.compressed_output_listing(self.paths)
+ else:
+ # In verbose mode, display all the files that are going to be
+ # deleted.
+ will_remove = list(self.paths)
+ will_skip = set()
+
_display('Would remove:', will_remove)
_display('Would not remove (might be manually added):', will_skip)
_display('Would not remove (outside of prefix):', self._refuse)
