def test_desktop_file(self): desktop_file_path = "foo.desktop" with open(desktop_file_path, "w") as desktop_file: print("[Desktop Entry]", file=desktop_file) print("Exec=in-snap-exe", file=desktop_file) open("command-chain", "w").close() os.chmod("command-chain", 0o755) app = application.Application.from_dict(app_name="foo", app_dict=dict( command="/foo", desktop=desktop_file_path)) desktop_file = desktop.DesktopFile( snap_name="foo", app_name=app.app_name, filename=app.desktop, prime_dir=self.path, ) desktop_file.write(gui_dir="gui") expected_desktop_file_path = os.path.join("gui", "foo.desktop") self.expectThat(app.to_dict(), Not(Contains("desktop"))) self.expectThat(expected_desktop_file_path, FileExists())
def _generate_desktop_file(self, name, app): # Extracted metadata (e.g. from the AppStream) can override the # icon location. if self._extracted_metadata: icon_path = self._extracted_metadata.get_icon() else: icon_path = None desktop_file_name = app.pop("desktop", "") if desktop_file_name: desktop_file = desktop.DesktopFile( snap_name=self._config_data["name"], app_name=name, filename=desktop_file_name, prime_dir=self._prime_dir, ) desktop_file.write(gui_dir=os.path.join(self.meta_dir, "gui"), icon_path=icon_path)