8000 Improves purging and shortcut removal. (#103) · python/pymanager@5ee86eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ee86eb

Browse files
authored
Improves purging and shortcut removal. (#103)
Fixes #102
1 parent 7e8c553 commit 5ee86eb

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/manage/pep514utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,23 @@ def update_registry(root_name, install, data, warn_for=[]):
256256

257257

258258
def cleanup_registry(root_name, keep, warn_for=[]):
259+
LOGGER.debug("Cleaning up registry entries")
259260
hive, name = _split_root(root_name)
260261
with _reg_open(hive, name, writable=True) as root:
261-
for company_name in _iter_keys(root):
262+
for company_name in list(_iter_keys(root)):
262263
any_left = False
263264
with winreg.OpenKey(root, company_name, access=winreg.KEY_ALL_ACCESS) as company:
264-
for tag_name in _iter_keys(company):
265+
for tag_name in list(_iter_keys(company)):
265266
# Calculate whether to show warnings or not
266267
install = {"company": company_name, "tag": tag_name}
267268
allow_warn = install_matches_any(install, warn_for)
268269

269270
if (f"{company_name}\\{tag_name}" in keep
270271
or not _is_tag_managed(company, tag_name, allow_warn=allow_warn)):
272+
LOGGER.debug("Skipping %s\\%s\\%s", root_name, company_name, tag_name)
271273
any_left = True
272274
else:
275+
LOGGER.debug("Removing %s\\%s\\%s", root_name, company_name, tag_name)
273276
_reg_rmtree(company, tag_name)
274277
if not any_left:
275278
_delete_key(root, company_name)

src/manage/uninstall_command.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from .exceptions import ArgumentError, FilesInUseError
22
from .fsutils import rmtree, unlink
33
from .installs import get_matching_install_tags
4-
from .install_command import update_all_shortcuts
4+
from .install_command import SHORTCUT_HANDLERS, update_all_shortcuts
55
from .logging import LOGGER
66
from .pathutils import PurePath
77
from .tagutils import tag_or_range
88

99

1010
def _iterdir(p, only_files=False):
1111
try:
12+
if only_files:
13+
return [f for f in p.iterdir() if p.is_file()]
1214
return list(p.iterdir())
1315
except FileNotFoundError:
1416
LOGGER.debug("Skipping %s because it does not exist", p)
@@ -42,18 +44,15 @@ def execute(cmd):
4244
LOGGER.warn("Unable to purge %s because it is still in use.",
4345
i["display-name"])
4446
continue
45-
LOGGER.info("Purging saved downloads")
46-
for f in _iterdir(cmd.install_dir):
47-
LOGGER.debug("Purging %s", f)
48-
try:
49-
rmtree(f, after_5s_warning=warn_msg.format("cached downloads"),
50-
remove_ext_first=("exe", "dll", "json"))
51-
except FilesInUseError:
52-
pass
53-
LOGGER.info("Purging global commands")
47+
LOGGER.info("Purging saved downloads from %s", cmd.download_dir)
48+
rmtree(cmd.download_dir, after_5s_warning=warn_msg.format("cached downloads"))
49+
LOGGER.info("Purging global commands from %s", cmd.global_dir)
5450
for f in _iterdir(cmd.global_dir):
5551
LOGGER.debug("Purging %s", f)
5652
rmtree(f, after_5s_warning=warn_msg.format("global commands"))
53+
LOGGER.info("Purging all shortcuts")
54+
for _, cleanup in SHORTCUT_HANDLERS.values():
55+
cleanup(cmd, [])
5756
LOGGER.debug("END uninstall_command.execute")
5857
return
5958

0 commit comments

Comments
 (0)
0