Skip to content

Commit

Permalink
Add removal feature to frameworks
Browse files Browse the repository at this point in the history
* All frameworks have now a --remove option enabling them to uninstall
  their desktop file, icon, projected content and udtc config.
* Add corresponding tests.
  • Loading branch information
didrocks committed Sep 16, 2014
1 parent c5c8086 commit 418c202
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
37 changes: 37 additions & 0 deletions tests/large/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,40 @@ def test_is_default_framework_with_options(self):
self.child = pexpect.spawnu(self.command('{} android /tmp/foo'.format(UDTC)))
self.expect_and_no_warn("\[I Accept.*\]") # ensure we have a license as the first question
self.accept_default_and_wait()

def test_removal(self):
"""Remove android studio with default path"""
self.child = pexpect.spawnu(self.command('{} android android-studio'.format(UDTC)))
self.expect_and_no_warn("Choose installation path: {}".format(self.installed_path))
self.child.sendline("")
self.expect_and_no_warn("\[.*\] ")
self.child.sendline("a")
self.expect_and_no_warn("Installation done", timeout=self.TIMEOUT_INSTALL_PROGRESS)
self.wait_and_no_warn()
self.assertTrue(self.launcher_exists_and_is_pinned(self.desktop_filename))
self.assertTrue(self.path_exists(self.installed_path))

# now, remove it
self.child = pexpect.spawnu(self.command('{} android android-studio --remove'.format(UDTC)))
self.wait_and_no_warn()

self.assertFalse(self.launcher_exists_and_is_pinned(self.desktop_filename))
self.assertFalse(self.path_exists(self.installed_path))

def test_removal_non_default_path(self):
"""Remove android studio with default path"""
self.installed_path = "/tmp/foo"
self.child = pexpect.spawnu(self.command('{} android android-studio {}'.format(UDTC, self.installed_path)))
self.expect_and_no_warn("\[.*\] ")
self.child.sendline("a")
self.expect_and_no_warn("Installation done", timeout=self.TIMEOUT_INSTALL_PROGRESS)
self.wait_and_no_warn()
self.assertTrue(self.launcher_exists_and_is_pinned(self.desktop_filename))
self.assertTrue(self.path_exists(self.installed_path))

# now, remove it
self.child = pexpect.spawnu(self.command('{} android android-studio --remove'.format(UDTC)))
self.wait_and_no_warn()

self.assertFalse(self.launcher_exists_and_is_pinned(self.desktop_filename))
self.assertFalse(self.path_exists(self.installed_path))
19 changes: 18 additions & 1 deletion udtc/frameworks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import abc
from contextlib import suppress
from gettext import gettext as _
from importlib import import_module, reload
import inspect
import logging
Expand Down Expand Up @@ -232,6 +233,13 @@ def setup(self):
# be a normal, kind user
switch_to_current_user()

@abc.abstractmethod
def remove(self):
"""Method call to remove the current framework"""
if not self.is_installed:
logger.error("You can't remove a framework that isn't installed")
UI.return_main_screen()
return

def mark_in_config(self):
"""Mark the installation as installed in the config file"""
Expand Down Expand Up @@ -261,12 +269,21 @@ def install_framework_parser(self, parser):
"""Install framework parser"""
this_framework_parser = parser.add_parser(self.prog_name, help=self.description)
this_framework_parser.add_argument('destdir', nargs='?')
this_framework_parser.add_argument('-r', '--remove', action="store_true",
help=_("Remove framework if installed"))
return this_framework_parser

def run_for(self, args):
"""Running commands from args namespace"""
logger.debug("Call run_for on {}".format(self.name))
self.setup(args.destdir)
if args.remove:
if args.destdir:
message = "You can't specify a destination dir while removing a framework"
logger.error(message)
raise BaseException(message)
self.remove()
else:
self.setup(args.destdir)


class MainCategory(BaseCategory):
Expand Down
24 changes: 23 additions & 1 deletion udtc/frameworks/baseinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from udtc.network.download_center import DownloadCenter
from udtc.network.requirements_handler import RequirementsHandler
from udtc.ui import UI
from udtc.tools import MainLoop, strip_tags, launcher_exists
from udtc.tools import MainLoop, strip_tags, launcher_exists, get_icon_path, get_launcher_path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,6 +91,28 @@ def reinstall(self):
self._paths_to_clean.add(self.install_path) # remove previous installation path
self.confirm_path(self.arg_install_path)

def remove(self):
"""Remove current framework if installed
Not that we only remove desktop file, launcher icon and dir content, we do not remove
packages as they might be in used for other framework"""
# check if it's installed and so on.
super().remove()

UI.display(DisplayMessage("Removing {}".format(self.name)))
if self.desktop_filename:
with suppress(FileNotFoundError):
os.remove(get_launcher_path(self.desktop_filename))
if self.icon_filename:
with suppress(FileNotFoundError):
os.remove(get_icon_path(self.icon_filename))
with suppress(FileNotFoundError):
shutil.rmtree(self.install_path)
self.remove_from_config()

UI.delayed_display(DisplayMessage("Suppression done"))
UI.return_main_screen()

def confirm_path(self, path_dir=""):
"""Confirm path dir"""

Expand Down

2 comments on commit 418c202

@Tinche
Copy link
Contributor

@Tinche Tinche commented on 418c202 Sep 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason this doesn't show up in --help, I had to look it up here.

@didrocks
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #28, tell me if you have any thought on the best approach to this.

Please sign in to comment.