Skip to content

Commit 2fea99c

Browse files
committed
Moved the view uninstallation to a separate function to mirror view_install
1 parent 5e29e93 commit 2fea99c

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

shpc/client/view.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,4 @@ def main(args, parser, extra, subparser):
175175
cli.view_install(view_name, module_name, force=args.force)
176176

177177
if command == "uninstall":
178-
cli.uninstall(module_name, view=view_name, force=args.force)
178+
cli.view_uninstall(view_name, module_name, force=args.force)

shpc/main/modules/base.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,34 @@ def modulefile(self):
6767
def templatefile(self):
6868
return "%s.%s" % (self.container.templatefile, self.module_extension)
6969

70-
def uninstall(self, name, view=None, force=False):
70+
def view_uninstall(self, view, name, force=False):
7171
"""
72-
Given a unique resource identifier, uninstall a module. If a view
73-
name is provided, assume we only want to uninstall from the view
72+
Uninstall a module from a view.
7473
"""
7574
module = self.new_module(name)
7675

77-
# We need to look for the module in all views and show to the user first
78-
views_with_module = set()
76+
# Ask before deleting anything!
77+
if not force:
78+
msg = name + "?"
79+
if not utils.confirm_uninstall(msg, force):
80+
return
81+
82+
# Only uninstall from the view
83+
if view not in self.views:
84+
logger.exit("View %s does not exist, cannot uninstall." % view)
85+
return self.views[view].uninstall(module.module_dir)
7986

80-
# Only populate if the command is not directed to a view
81-
if not view:
87+
def uninstall(self, name, force=False):
88+
"""
89+
Given a unique resource identifier, uninstall a module.
90+
"""
91+
module = self.new_module(name)
8292

83-
# If uninstalling the entire module, clean up symbolic links in all views
84-
for view_name, entry in self.views.items():
85-
if entry.exists(module.module_dir):
86-
views_with_module.add(view_name)
93+
# We need to look for the module in all views and show to the user first
94+
views_with_module = set()
95+
for view_name, entry in self.views.items():
96+
if entry.exists(module.module_dir):
97+
views_with_module.add(view_name)
8798

8899
# Ask before deleting anything!
89100
if not force:
@@ -96,12 +107,6 @@ def uninstall(self, name, view=None, force=False):
96107
if not utils.confirm_uninstall(msg, force):
97108
return
98109

99-
# Only uninstall from the view
100-
if view:
101-
if view not in self.views:
102-
logger.exit("View %s does not exist, cannot uninstall." % view)
103-
return self.views[view].uninstall(module.module_dir)
104-
105110
# Podman needs image deletion
106111
self.container.delete(module.name)
107112

@@ -124,8 +129,8 @@ def uninstall(self, name, view=None, force=False):
124129
)
125130

126131
# If uninstalling the entire module, clean up symbolic links in all views
127-
for view_name, view in self.views.items():
128-
view.uninstall(module.module_dir)
132+
for view_name in views_with_module:
133+
self.views[view_name].uninstall(module.module_dir)
129134

130135
# parent of versioned directory has module .version
131136
module_dir = os.path.dirname(module.module_dir)

shpc/tests/test_views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
9595
module_file = os.path.join(module_path, module_file[0])
9696
assert os.path.islink(module_file)
9797

98-
client.uninstall("ghcr.io/autamus/emacs:27.2", view=view_name, force=True)
98+
client.view_uninstall(view_name, "ghcr.io/autamus/emacs:27.2", force=True)
9999

100100
# The view should be removed
101101
assert "emacs" not in os.listdir(os.path.join(view.path))

0 commit comments

Comments
 (0)