def test_remove_user_env_no_file(self, expanderusermock): """Remove an env from a user setup with no profile file""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") tools.remove_framework_envs_from_user("framework A") self.assertRaises(FileNotFoundError, open, profile_file)
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)) os.remove( os.path.join(self.default_binary_link_path, self.exec_link_name)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) path = os.path.dirname(self.install_path) while path is not DEFAULT_INSTALL_TOOLS_PATH: if os.listdir(path) == []: logger.debug( "Empty folder, cleaning recursively: {}".format(path)) os.rmdir(path) path = os.path.dirname(path) else: break remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
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)) os.remove( os.path.join(self.default_binary_link_path, self.exec_link_name)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def test_remove_user_env_not_found(self, expanderusermock): """Remove an env from a user setup with no matching content found""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, 'w').write("Foo\nBar\nexport BAR=baz") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEqual(profile_content, "Foo\nBar\nexport BAR=baz")
def test_remove_user_env_end(self, expanderusermock): """Remove an env from a user setup being at the end of profile file""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, "w").write("Foo\nBar\n# Ubuntu make installation of framework A" "\nexport FOO=bar\n\n") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEqual(profile_content, "Foo\nBar\n")
def test_remove_user_multiple_same_framework(self, expanderusermock): """Remove an env from a user setup, same framework being repeated multiple times""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, 'w').write("Foo\nBar\n# Ubuntu make installation of framework A\nexport BAR=bar\n\n" "# Ubuntu make installation of framework A\nexport FOO=bar\n\nexport BAR=baz") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEqual(profile_content, "Foo\nBar\nexport BAR=baz")
def test_remove_user_env_end(self, expanderusermock): """Remove an env from a user setup being at the end of profile file""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, 'w').write("Foo\nBar\n# Ubuntu make installation of framework A" "\nexport FOO=bar\n\n") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEqual(profile_content, "Foo\nBar\n")
def test_remove_user_env_multiple_frameworks(self, expanderusermock): """Remove an env from a user setup restraining to the correct framework""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, 'w').write("Foo\nBar\n# Ubuntu make installation of framework B\nexport BAR=bar\n\n" "# Ubuntu make installation of framework A\nexport FOO=bar\n\nexport BAR=baz") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEquals(profile_content, "Foo\nBar\n# Ubuntu make installation of framework B\nexport BAR=bar\n\n" "export BAR=baz")
def test_remove_user_env_zsh(self, expanderusermock): """Remove an env from a user setup using zsh""" os.environ['SHELL'] = '/bin/zsh' expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".zprofile") open(profile_file, 'w').write("Foo\nBar\n# Ubuntu make installation of framework A" "\nexport FOO=bar\n\nexport BAR=baz") tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEqual(profile_content, "Foo\nBar\nexport BAR=baz")
def test_remove_user_env_multiple_frameworks(self, expanderusermock): """Remove an env from a user setup restraining to the correct framework""" expanderusermock.return_value = self.local_dir profile_file = os.path.join(self.local_dir, ".profile") open(profile_file, 'w').write( "Foo\nBar\n# Ubuntu make installation of framework B\nexport BAR=bar\n\n" "# Ubuntu make installation of framework A\nexport FOO=bar\n\nexport BAR=baz" ) tools.remove_framework_envs_from_user("framework A") profile_content = open(profile_file).read() self.assertEquals( profile_content, "Foo\nBar\n# Ubuntu make installation of framework B\nexport BAR=bar\n\n" "export BAR=baz")
def tearDown(self): # don't remove on machine paths if running within a container if not self.in_container: with suppress(FileNotFoundError): shutil.rmtree(self.installed_path) # TODO: need to be finer grain in the future with suppress(FileNotFoundError): os.remove(self.conf_path) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) remove_framework_envs_from_user(self.framework_name_for_profile) for dir in self.additional_dirs: with suppress(OSError): shutil.rmtree(dir) super().tearDown()
def tearDown(self): # don't remove on machine paths if running within a container if not self.in_container: with suppress(FileNotFoundError): shutil.rmtree(self.installed_path) # TODO: need to be finer grain in the future with suppress(FileNotFoundError): os.remove(self.conf_path) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) remove_framework_envs_from_user(self.framework_name_for_profile) for dir in self.additional_dirs: with suppress(OSError): shutil.rmtree(dir) # restore original environment. Do not use the dict copy which erases the object and doesn't have the magical # _Environ which setenv() for subprocess os.environ.clear() os.environ.update(self.original_env) super().tearDown()
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) remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def reinstall(self): logger.debug("Mark previous installation path for cleaning.") self._paths_to_clean.add( self.install_path) # remove previous installation path self.confirm_path(self.arg_install_path) remove_framework_envs_from_user(self.name)
def reinstall(self): logger.debug("Mark previous installation path for cleaning.") self._paths_to_clean.add(self.install_path) # remove previous installation path self.confirm_path(self.arg_install_path) remove_framework_envs_from_user(self.name)