Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/manage/pep514utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,23 @@


def cleanup_registry(root_name, keep, warn_for=[]):
LOGGER.debug("Cleaning up registry entries")

Check warning on line 259 in src/manage/pep514utils.py

View check run for this annotation

Codecov / codecov/patch

src/manage/pep514utils.py#L259

Added line #L259 was not covered by tests
hive, name = _split_root(root_name)
with _reg_open(hive, name, writable=True) as root:
for company_name in _iter_keys(root):
for company_name in list(_iter_keys(root)):
any_left = False
with winreg.OpenKey(root, company_name, access=winreg.KEY_ALL_ACCESS) as company:
for tag_name in _iter_keys(company):
for tag_name in list(_iter_keys(company)):
# Calculate whether to show warnings or not
install = {"company": company_name, "tag": tag_name}
allow_warn = install_matches_any(install, warn_for)

if (f"{company_name}\\{tag_name}" in keep
or not _is_tag_managed(company, tag_name, allow_warn=allow_warn)):
LOGGER.debug("Skipping %s\\%s\\%s", root_name, company_name, tag_name)

Check warning on line 272 in src/manage/pep514utils.py

View check run for this annotation

Codecov / codecov/patch

src/manage/pep514utils.py#L272

Added line #L272 was not covered by tests
any_left = True
else:
LOGGER.debug("Removing %s\\%s\\%s", root_name, company_name, tag_name)

Check warning on line 275 in src/manage/pep514utils.py

View check run for this annotation

Codecov / codecov/patch

src/manage/pep514utils.py#L275

Added line #L275 was not covered by tests
_reg_rmtree(company, tag_name)
if not any_left:
_delete_key(root, company_name)
Expand Down
19 changes: 9 additions & 10 deletions src/manage/uninstall_command.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from .exceptions import ArgumentError, FilesInUseError
from .fsutils import rmtree, unlink
from .installs import get_matching_install_tags
from .install_command import update_all_shortcuts
from .install_command import SHORTCUT_HANDLERS, update_all_shortcuts

Check warning on line 4 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L4

Added line #L4 was not covered by tests
from .logging import LOGGER
from .pathutils import PurePath
from .tagutils import tag_or_range


def _iterdir(p, only_files=False):
try:
if only_files:
return [f for f in p.iterdir() if p.is_file()]

Check warning on line 13 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L13

Added line #L13 was not covered by tests
return list(p.iterdir())
except FileNotFoundError:
LOGGER.debug("Skipping %s because it does not exist", p)
Expand Down Expand Up @@ -42,18 +44,15 @@
LOGGER.warn("Unable to purge %s because it is still in use.",
i["display-name"])
continue
LOGGER.info("Purging saved downloads")
for f in _iterdir(cmd.install_dir):
LOGGER.debug("Purging %s", f)
try:
rmtree(f, after_5s_warning=warn_msg.format("cached downloads"),
remove_ext_first=("exe", "dll", "json"))
except FilesInUseError:
pass
LOGGER.info("Purging global commands")
LOGGER.info("Purging saved downloads from %s", cmd.download_dir)
rmtree(cmd.download_dir, after_5s_warning=warn_msg.format("cached downloads"))
LOGGER.info("Purging global commands from %s", cmd.global_dir)

Check warning on line 49 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L47-L49

Added lines #L47 - L49 were not covered by tests
for f in _iterdir(cmd.global_dir):
LOGGER.debug("Purging %s", f)
rmtree(f, after_5s_warning=warn_msg.format("global commands"))
LOGGER.info("Purging all shortcuts")

Check warning on line 53 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L53

Added line #L53 was not covered by tests
for _, cleanup in SHORTCUT_HANDLERS.values():
cleanup(cmd, [])

Check warning on line 55 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L55

Added line #L55 was not covered by tests
LOGGER.debug("END uninstall_command.execute")
return

Expand Down