Skip to content

Commit

Permalink
Moved the view uninstallation to a separate function to mirror view_i…
Browse files Browse the repository at this point in the history
…nstall
  • Loading branch information
muffato committed Oct 11, 2022
1 parent 5e29e93 commit 2fea99c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion shpc/client/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ def main(args, parser, extra, subparser):
cli.view_install(view_name, module_name, force=args.force)

if command == "uninstall":
cli.uninstall(module_name, view=view_name, force=args.force)
cli.view_uninstall(view_name, module_name, force=args.force)
43 changes: 24 additions & 19 deletions shpc/main/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,34 @@ def modulefile(self):
def templatefile(self):
return "%s.%s" % (self.container.templatefile, self.module_extension)

def uninstall(self, name, view=None, force=False):
def view_uninstall(self, view, name, force=False):
"""
Given a unique resource identifier, uninstall a module. If a view
name is provided, assume we only want to uninstall from the view
Uninstall a module from a view.
"""
module = self.new_module(name)

# We need to look for the module in all views and show to the user first
views_with_module = set()
# Ask before deleting anything!
if not force:
msg = name + "?"
if not utils.confirm_uninstall(msg, force):
return

# Only uninstall from the view
if view not in self.views:
logger.exit("View %s does not exist, cannot uninstall." % view)
return self.views[view].uninstall(module.module_dir)

# Only populate if the command is not directed to a view
if not view:
def uninstall(self, name, force=False):
"""
Given a unique resource identifier, uninstall a module.
"""
module = self.new_module(name)

# If uninstalling the entire module, clean up symbolic links in all views
for view_name, entry in self.views.items():
if entry.exists(module.module_dir):
views_with_module.add(view_name)
# We need to look for the module in all views and show to the user first
views_with_module = set()
for view_name, entry in self.views.items():
if entry.exists(module.module_dir):
views_with_module.add(view_name)

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

# Only uninstall from the view
if view:
if view not in self.views:
logger.exit("View %s does not exist, cannot uninstall." % view)
return self.views[view].uninstall(module.module_dir)

# Podman needs image deletion
self.container.delete(module.name)

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

# If uninstalling the entire module, clean up symbolic links in all views
for view_name, view in self.views.items():
view.uninstall(module.module_dir)
for view_name in views_with_module:
self.views[view_name].uninstall(module.module_dir)

# parent of versioned directory has module .version
module_dir = os.path.dirname(module.module_dir)
Expand Down
2 changes: 1 addition & 1 deletion shpc/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
module_file = os.path.join(module_path, module_file[0])
assert os.path.islink(module_file)

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

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

0 comments on commit 2fea99c

Please sign in to comment.