def test_can_update_launcher(self, SettingsMock): """Update a launcher file""" SettingsMock.list_schemas.return_value = [ "foo", "bar", "com.canonical.Unity.Launcher", "baz" ] SettingsMock.return_value.get_strv.return_value = [ "application://bar.desktop", "unity://running-apps" ] create_launcher("foo.desktop", self.get_generic_desktop_content()) new_content = dedent("""\ [Desktop Entry] Version=1.0 Type=Application Name=Android Studio 2 Icon=/home/didrocks/{install_dir}/android-studio/bin/idea2.png Exec="/home/didrocks/{install_dir}/android-studio/bin/studio2.sh" %f Comment=Develop with pleasure! Categories=Development;IDE; Terminal=false StartupWMClass=jetbrains-android-studio """.format(install_dir=INSTALL_DIR)) create_launcher("foo.desktop", new_content) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop"))) self.assertEqual( open(get_launcher_path("foo.desktop")).read(), new_content)
def test_can_install(self, SettingsMock): """Install a basic launcher, default case with unity://running""" SettingsMock.list_schemas.return_value = ["foo", "bar", "com.canonical.Unity.Launcher", "baz"] SettingsMock.return_value.get_strv.return_value = ["application://bar.desktop", "unity://running-apps"] create_launcher("foo.desktop", self.get_generic_desktop_content()) self.assertTrue(SettingsMock.list_schemas.called) SettingsMock.return_value.get_strv.assert_called_with("favorites") SettingsMock.return_value.set_strv.assert_called_with("favorites", ["application://bar.desktop", "application://foo.desktop", "unity://running-apps"]) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop"))) self.assertEqual(open(get_launcher_path("foo.desktop")).read(), self.get_generic_desktop_content())
def test_create_launcher_without_xdg_dir(self, SettingsMock): """Save a new launcher in an unexisting directory""" shutil.rmtree(self.local_dir) SettingsMock.list_schemas.return_value = ["foo", "bar", "baz"] create_launcher("foo.desktop", self.get_generic_desktop_content()) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop")))
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 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 get_path_from_desktop_file(desktop_filename, key): """get the path referred as key in the desktop filename exists""" if not desktop_filename: return "" from umake.tools import get_launcher_path importlib.reload(xdg.BaseDirectory) path = "" with open(get_launcher_path(desktop_filename)) as f: for line in f: p = re.search(r'{}=(.*)'.format(key), line) with suppress(AttributeError): path = p.group(1) # sanitize the field with unescaped quotes for separator in ('"', "'", " "): elem_paths = path.split(separator) path = "" for elem in elem_paths: if not elem: continue # the separator was escaped, read the separator element if elem[-1] == "\\": elem += separator path += elem # stop for current sep at first unescaped separator if not path.endswith("\\" + separator): break return path
def test_install_no_schema_file(self, SettingsMock): """No schema file still installs the file""" SettingsMock.list_schemas.return_value = ["foo", "bar", "baz"] create_launcher("foo.desktop", self.get_generic_desktop_content()) self.assertFalse(SettingsMock.return_value.get_strv.called) self.assertFalse(SettingsMock.return_value.set_strv.called) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop")))
def get_desktop_file_path(desktop_filename): """get the desktop file path""" if not desktop_filename: return "" from umake.tools import get_launcher_path importlib.reload(xdg.BaseDirectory) return get_launcher_path(desktop_filename)
def test_can_install_already_in_launcher(self, SettingsMock): """A file listed in launcher still install the files, but the entry isn't changed""" SettingsMock.list_schemas.return_value = ["foo", "bar", "com.canonical.Unity.Launcher", "baz"] SettingsMock.return_value.get_strv.return_value = ["application://bar.desktop", "application://foo.desktop", "unity://running-apps"] create_launcher("foo.desktop", self.get_generic_desktop_content()) self.assertFalse(SettingsMock.return_value.set_strv.called) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop")))
def test_can_update_launcher(self, SettingsMock): """Update a launcher file""" SettingsMock.list_schemas.return_value = ["foo", "bar", "com.canonical.Unity.Launcher", "baz"] SettingsMock.return_value.get_strv.return_value = ["application://bar.desktop", "unity://running-apps"] create_launcher("foo.desktop", self.get_generic_desktop_content()) new_content = dedent("""\ [Desktop Entry] Version=1.0 Type=Application Name=Android Studio 2 Icon=/home/didrocks/tools/android-studio/bin/idea2.png Exec="/home/didrocks/tools/android-studio/bin/studio2.sh" %f Comment=Develop with pleasure! Categories=Development;IDE; Terminal=false StartupWMClass=jetbrains-android-studio """) create_launcher("foo.desktop", new_content) self.assertTrue(os.path.exists(get_launcher_path("foo.desktop"))) self.assertEqual(open(get_launcher_path("foo.desktop")).read(), new_content)
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) with suppress(FileNotFoundError): os.remove(self.conf_path) with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) with suppress(FileNotFoundError): if self.icon_filename: os.remove(get_icon_path(self.icon_filename)) 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) 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 test_get_launcher_path(self): """Get correct launcher path""" self.assertEqual(get_launcher_path("foo.desktop"), os.path.join(self.local_dir, "applications", "foo.desktop"))
def get_launcher_path(self, desktop_filename): """passthrough getting the launcher path from umake tools""" return get_launcher_path(desktop_filename)
def test_get_launcher_path(self): """Get correct launcher path""" self.assertEqual( get_launcher_path("foo.desktop"), os.path.join(self.local_dir, "applications", "foo.desktop"))