From 9c2b395aa0ff7b3ca93d8f09a70edff779ff0097 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 1 Aug 2023 19:47:12 -0700 Subject: [PATCH 01/12] Add support for mapping GUI resources to a host path for improved container support --- README.md | 8 +++++++- ovos_gui/bus.py | 6 ++++-- ovos_gui/namespace.py | 15 ++++++++++----- ovos_gui/page.py | 3 ++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4718cd5..8d704f8 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,13 @@ under mycroft.conf // Optional file server support for remote clients // "gui_file_server": true, // "file_server_port": 8000, - + + // Optional support for collecting GUI files for container support + // This example describes a configuration where the host system has mounted + // `/tmp/gui_files` to the container path `/mount/gui_files` + // "gui_file_host_path": "/tmp/gui_files" + // "server_path": "/mount/gui_files" + // Optionally specify a default qt version for connected clients that don't report it "default_qt_version": 5 }, diff --git a/ovos_gui/bus.py b/ovos_gui/bus.py index 4450a4e..0c82233 100644 --- a/ovos_gui/bus.py +++ b/ovos_gui/bus.py @@ -132,7 +132,8 @@ def get_client_pages(self, namespace): """ client_pages = [] server_url = self.ns_manager.gui_file_server.url if \ - self.ns_manager.gui_file_server else None + self.ns_manager.gui_file_server else \ + self.ns_manager.gui_file_host_path for page in namespace.pages: uri = page.get_uri(self.framework, server_url) client_pages.append(uri) @@ -260,7 +261,8 @@ def send_gui_pages(self, pages: List[GuiPage], namespace: str, @param position: position to insert pages at """ server_url = self.ns_manager.gui_file_server.url if \ - self.ns_manager.gui_file_server else None + self.ns_manager.gui_file_server else \ + self.ns_manager.gui_file_host_path framework = self.framework message = { diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 54bff59..da5940e 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -459,24 +459,29 @@ def __init__(self, core_bus: MessageBusClient): self._ready_event = Event() self.gui_file_server = None self.gui_file_path = None + self.gui_file_host_path = None self._connected_frameworks: List[str] = list() - self._init_gui_server() + self._init_gui_file_share() self._define_message_handlers() @property def _active_homescreen(self) -> str: return Configuration().get('gui', {}).get('idle_display_skill') - def _init_gui_server(self): + def _init_gui_file_share(self): """ - Initialize a GUI HTTP file server if enabled in configuration + Initialize optional GUI file collection. if `gui_file_host_path` is + defined, resources are assumed to be referenced outside this container. + If `gui_file_server` is defined, resources will be served via HTTP """ config = Configuration().get("gui", {}) - if config.get("gui_file_server", False): + self.gui_file_host_path = config.get("gui_file_host_path") + if config.get("gui_file_server") or self.gui_file_host_path: from ovos_utils.file_utils import get_temp_path self.gui_file_path = config.get("server_path") or \ get_temp_path("ovos_gui_file_server") - self.gui_file_server = start_gui_http_server(self.gui_file_path) + if config.get("gui_file_server"): + self.gui_file_server = start_gui_http_server(self.gui_file_path) self._upload_system_resources() def _define_message_handlers(self): diff --git a/ovos_gui/page.py b/ovos_gui/page.py index 9ec77ce..3bbb7ce 100644 --- a/ovos_gui/page.py +++ b/ovos_gui/page.py @@ -50,7 +50,8 @@ def get_uri(self, framework: str = "qt5", server_url: str = None) -> str: """ Get a valid URI for this Page. @param framework: String GUI framework to get resources for - @param server_url: String server URL if available + @param server_url: String server URL if available; this could be for a + web server (http://), or a container host path (file://) @return: Absolute path to the requested resource """ if self.url: From 02656577f617bca805b63351d84f3ad332596cea Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 18:00:36 -0700 Subject: [PATCH 02/12] Update default GUI file path and documentation to address PR feedback --- README.md | 8 ++++---- ovos_gui/bus.py | 4 ++-- ovos_gui/namespace.py | 12 ++++++------ test/unittests/test_namespace.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8d704f8..c777891 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,10 @@ under mycroft.conf // "file_server_port": 8000, // Optional support for collecting GUI files for container support - // This example describes a configuration where the host system has mounted - // `/tmp/gui_files` to the container path `/mount/gui_files` - // "gui_file_host_path": "/tmp/gui_files" - // "server_path": "/mount/gui_files" + // This example describes a configuration where the HOST system has collected + // GUI resources at `/tmp/gui_files`. The container path for these files will be + // {XDG_CACHE_HOME}/ovos_gui_file_server + // "ui_file_path": "/tmp/gui_files" // Optionally specify a default qt version for connected clients that don't report it "default_qt_version": 5 diff --git a/ovos_gui/bus.py b/ovos_gui/bus.py index 0c82233..1b3879b 100644 --- a/ovos_gui/bus.py +++ b/ovos_gui/bus.py @@ -133,7 +133,7 @@ def get_client_pages(self, namespace): client_pages = [] server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_host_path + self.ns_manager.ui_file_path for page in namespace.pages: uri = page.get_uri(self.framework, server_url) client_pages.append(uri) @@ -262,7 +262,7 @@ def send_gui_pages(self, pages: List[GuiPage], namespace: str, """ server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_host_path + self.ns_manager.ui_file_path framework = self.framework message = { diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index da5940e..a8de7e0 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -459,7 +459,7 @@ def __init__(self, core_bus: MessageBusClient): self._ready_event = Event() self.gui_file_server = None self.gui_file_path = None - self.gui_file_host_path = None + self.ui_file_path = None self._connected_frameworks: List[str] = list() self._init_gui_file_share() self._define_message_handlers() @@ -470,16 +470,16 @@ def _active_homescreen(self) -> str: def _init_gui_file_share(self): """ - Initialize optional GUI file collection. if `gui_file_host_path` is + Initialize optional GUI file collection. if `ui_file_path` is defined, resources are assumed to be referenced outside this container. If `gui_file_server` is defined, resources will be served via HTTP """ config = Configuration().get("gui", {}) - self.gui_file_host_path = config.get("gui_file_host_path") - if config.get("gui_file_server") or self.gui_file_host_path: - from ovos_utils.file_utils import get_temp_path + self.ui_file_path = config.get("ui_file_path") + if config.get("gui_file_server") or self.ui_file_path: + from ovos_utils.xdg_utils import xdg_cache_home self.gui_file_path = config.get("server_path") or \ - get_temp_path("ovos_gui_file_server") + join(xdg_cache_home(), "ovos_gui_file_server") if config.get("gui_file_server"): self.gui_file_server = start_gui_http_server(self.gui_file_path) self._upload_system_resources() diff --git a/test/unittests/test_namespace.py b/test/unittests/test_namespace.py index cdd08f3..8a3fec6 100644 --- a/test/unittests/test_namespace.py +++ b/test/unittests/test_namespace.py @@ -202,7 +202,7 @@ def setUp(self): with mock.patch(PATCH_MODULE + ".create_gui_service"): self.namespace_manager = NamespaceManager(FakeBus()) - def test_init_gui_server(self): + def test_init_gui_file_share(self): # TODO pass From e02441f036edf7ff784b67a1ff6d0bc82771a585 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 18:05:37 -0700 Subject: [PATCH 03/12] Update documented configuration --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c777891..5117cd7 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ under mycroft.conf // This example describes a configuration where the HOST system has collected // GUI resources at `/tmp/gui_files`. The container path for these files will be // {XDG_CACHE_HOME}/ovos_gui_file_server - // "ui_file_path": "/tmp/gui_files" + // "ui_file_path": "/tmp/gui_files", // Optionally specify a default qt version for connected clients that don't report it "default_qt_version": 5 From c27ca3f06ed3eeeab459995708027bb129d8c06f Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 18:40:22 -0700 Subject: [PATCH 04/12] Troubleshoot test failure Revert refactored config change to match existing parameter name --- README.md | 2 +- ovos_gui/bus.py | 4 ++-- ovos_gui/namespace.py | 7 +++---- test/unittests/test_bus.py | 8 ++++++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5117cd7..a772b0b 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ under mycroft.conf // This example describes a configuration where the HOST system has collected // GUI resources at `/tmp/gui_files`. The container path for these files will be // {XDG_CACHE_HOME}/ovos_gui_file_server - // "ui_file_path": "/tmp/gui_files", + // "gui_file_path": "/tmp/gui_files", // Optionally specify a default qt version for connected clients that don't report it "default_qt_version": 5 diff --git a/ovos_gui/bus.py b/ovos_gui/bus.py index 1b3879b..29bc669 100644 --- a/ovos_gui/bus.py +++ b/ovos_gui/bus.py @@ -133,7 +133,7 @@ def get_client_pages(self, namespace): client_pages = [] server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.ui_file_path + self.ns_manager.gui_file_path for page in namespace.pages: uri = page.get_uri(self.framework, server_url) client_pages.append(uri) @@ -262,7 +262,7 @@ def send_gui_pages(self, pages: List[GuiPage], namespace: str, """ server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.ui_file_path + self.ns_manager.gui_file_path framework = self.framework message = { diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index a8de7e0..1ea0a58 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -459,7 +459,6 @@ def __init__(self, core_bus: MessageBusClient): self._ready_event = Event() self.gui_file_server = None self.gui_file_path = None - self.ui_file_path = None self._connected_frameworks: List[str] = list() self._init_gui_file_share() self._define_message_handlers() @@ -470,13 +469,13 @@ def _active_homescreen(self) -> str: def _init_gui_file_share(self): """ - Initialize optional GUI file collection. if `ui_file_path` is + Initialize optional GUI file collection. if `gui_file_path` is defined, resources are assumed to be referenced outside this container. If `gui_file_server` is defined, resources will be served via HTTP """ config = Configuration().get("gui", {}) - self.ui_file_path = config.get("ui_file_path") - if config.get("gui_file_server") or self.ui_file_path: + self.gui_file_path = config.get("gui_file_path") + if config.get("gui_file_server") or self.gui_file_path: from ovos_utils.xdg_utils import xdg_cache_home self.gui_file_path = config.get("server_path") or \ join(xdg_cache_home(), "ovos_gui_file_server") diff --git a/test/unittests/test_bus.py b/test/unittests/test_bus.py index 862d8bd..1ee9c94 100644 --- a/test/unittests/test_bus.py +++ b/test/unittests/test_bus.py @@ -89,6 +89,10 @@ def test_get_client_pages(self): page_2.get_uri.return_value = "page_2_uri" test_namespace.pages = [page_1, page_2] + # Specify no host path mapping + self.handler.ns_manager.gui_file_path = None + # TODO: Test with host path mapping + # Test no server_url self.handler.ns_manager.gui_file_server = None pages = self.handler.get_client_pages(test_namespace) @@ -129,6 +133,10 @@ def test_send_gui_pages(self): page_2 = GuiPage(None, "", False, False) page_2.get_uri = Mock(return_value="page_2") + # Specify no host path mapping + self.handler.ns_manager.gui_file_path = None + # TODO: Test with host path mapping + # Test no server_url self.handler.ns_manager.gui_file_server = None self.handler._framework = "qt5" From 2cc7383568823beb7cf75adeac6652a8d3203112 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 18:59:56 -0700 Subject: [PATCH 05/12] Add test coverage for mapped path without server --- test/unittests/test_bus.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/unittests/test_bus.py b/test/unittests/test_bus.py index 1ee9c94..67cdd7f 100644 --- a/test/unittests/test_bus.py +++ b/test/unittests/test_bus.py @@ -91,7 +91,6 @@ def test_get_client_pages(self): # Specify no host path mapping self.handler.ns_manager.gui_file_path = None - # TODO: Test with host path mapping # Test no server_url self.handler.ns_manager.gui_file_server = None @@ -100,6 +99,14 @@ def test_get_client_pages(self): page_2.get_uri.assert_called_once_with(self.handler.framework, None) self.assertEqual(pages, ["page_1_uri", "page_2_uri"]) + # Test host path mapping + test_path = "/test/ovos-gui-file-server" + self.handler.ns_manager.gui_file_path = test_path + pages = self.handler.get_client_pages(test_namespace) + page_1.get_uri.assert_called_with(self.handler.framework, test_path) + page_2.get_uri.assert_called_with(self.handler.framework, test_path) + self.assertEqual(pages, ["page_1_uri", "page_2_uri"]) + # Test with server_url self.handler.ns_manager.gui_file_server = Mock() self.handler.ns_manager.gui_file_server.url = "server_url" @@ -135,7 +142,6 @@ def test_send_gui_pages(self): # Specify no host path mapping self.handler.ns_manager.gui_file_path = None - # TODO: Test with host path mapping # Test no server_url self.handler.ns_manager.gui_file_server = None @@ -149,6 +155,13 @@ def test_send_gui_pages(self): "position": test_pos, "data": [{"url": "page_1"}, {"url": "page_2"}]}) + # Test host path mapping + test_path = "/test/ovos-gui-file-server" + self.handler.ns_manager.gui_file_path = test_path + self.handler.send_gui_pages([page_1, page_2], test_ns, test_pos) + page_1.get_uri.assert_called_with(self.handler.framework, test_path) + page_2.get_uri.assert_called_with(self.handler.framework, test_path) + # Test with server_url self.handler.ns_manager.gui_file_server = Mock() self.handler.ns_manager.gui_file_server.url = "server_url" From f9ed2132d284980c7d5cf90dbda308a3c04bd433 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 19:14:16 -0700 Subject: [PATCH 06/12] Refactor to resolve variable overlap --- README.md | 2 +- ovos_gui/bus.py | 4 ++-- ovos_gui/gui_file_server.py | 6 ++++++ ovos_gui/namespace.py | 9 +++++---- test/unittests/test_bus.py | 8 ++++---- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a772b0b..66a70c4 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ under mycroft.conf // This example describes a configuration where the HOST system has collected // GUI resources at `/tmp/gui_files`. The container path for these files will be // {XDG_CACHE_HOME}/ovos_gui_file_server - // "gui_file_path": "/tmp/gui_files", + // "gui_file_host_path": "/tmp/gui_files", // Optionally specify a default qt version for connected clients that don't report it "default_qt_version": 5 diff --git a/ovos_gui/bus.py b/ovos_gui/bus.py index 29bc669..0c82233 100644 --- a/ovos_gui/bus.py +++ b/ovos_gui/bus.py @@ -133,7 +133,7 @@ def get_client_pages(self, namespace): client_pages = [] server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_path + self.ns_manager.gui_file_host_path for page in namespace.pages: uri = page.get_uri(self.framework, server_url) client_pages.append(uri) @@ -262,7 +262,7 @@ def send_gui_pages(self, pages: List[GuiPage], namespace: str, """ server_url = self.ns_manager.gui_file_server.url if \ self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_path + self.ns_manager.gui_file_host_path framework = self.framework message = { diff --git a/ovos_gui/gui_file_server.py b/ovos_gui/gui_file_server.py index 50abaf4..8b352c1 100644 --- a/ovos_gui/gui_file_server.py +++ b/ovos_gui/gui_file_server.py @@ -23,6 +23,12 @@ def end_headers(self) -> None: def start_gui_http_server(qml_path: str, port: int = None): + """ + Start an http server to host GUI Resources + @param qml_path: Local file path to server + @param port: Host port to run file server on + @return: Initialized HTTP Server + """ port = port or Configuration().get("gui", {}).get("file_server_port", 8089) if os.path.exists(qml_path): diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 1ea0a58..525a358 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -458,7 +458,8 @@ def __init__(self, core_bus: MessageBusClient): self._system_res_dir = join(dirname(__file__), "res", "gui") self._ready_event = Event() self.gui_file_server = None - self.gui_file_path = None + self.gui_file_path = None # HTTP Server local path + self.gui_file_host_path = None # Docker host path self._connected_frameworks: List[str] = list() self._init_gui_file_share() self._define_message_handlers() @@ -474,7 +475,7 @@ def _init_gui_file_share(self): If `gui_file_server` is defined, resources will be served via HTTP """ config = Configuration().get("gui", {}) - self.gui_file_path = config.get("gui_file_path") + self.gui_file_host_path = config.get("gui_file_host_path") if config.get("gui_file_server") or self.gui_file_path: from ovos_utils.xdg_utils import xdg_cache_home self.gui_file_path = config.get("server_path") or \ @@ -511,8 +512,8 @@ def handle_gui_pages_available(self, message: Message): GUI framework. @param message: `gui.volunteer_page_upload` message """ - if not self.gui_file_path: - LOG.debug("No GUI file server running") + if not self.gui_file_path and not self.gui_file_server: + LOG.debug("No GUI file server running or host path configured") return LOG.debug(f"Requesting resources for {self._connected_frameworks}") diff --git a/test/unittests/test_bus.py b/test/unittests/test_bus.py index 67cdd7f..c6ecd41 100644 --- a/test/unittests/test_bus.py +++ b/test/unittests/test_bus.py @@ -90,7 +90,7 @@ def test_get_client_pages(self): test_namespace.pages = [page_1, page_2] # Specify no host path mapping - self.handler.ns_manager.gui_file_path = None + self.handler.ns_manager.gui_file_host_path = None # Test no server_url self.handler.ns_manager.gui_file_server = None @@ -101,7 +101,7 @@ def test_get_client_pages(self): # Test host path mapping test_path = "/test/ovos-gui-file-server" - self.handler.ns_manager.gui_file_path = test_path + self.handler.ns_manager.gui_file_host_path = test_path pages = self.handler.get_client_pages(test_namespace) page_1.get_uri.assert_called_with(self.handler.framework, test_path) page_2.get_uri.assert_called_with(self.handler.framework, test_path) @@ -141,7 +141,7 @@ def test_send_gui_pages(self): page_2.get_uri = Mock(return_value="page_2") # Specify no host path mapping - self.handler.ns_manager.gui_file_path = None + self.handler.ns_manager.gui_file_host_path = None # Test no server_url self.handler.ns_manager.gui_file_server = None @@ -157,7 +157,7 @@ def test_send_gui_pages(self): # Test host path mapping test_path = "/test/ovos-gui-file-server" - self.handler.ns_manager.gui_file_path = test_path + self.handler.ns_manager.gui_file_host_path = test_path self.handler.send_gui_pages([page_1, page_2], test_ns, test_pos) page_1.get_uri.assert_called_with(self.handler.framework, test_path) page_2.get_uri.assert_called_with(self.handler.framework, test_path) From f1511e0c783724197e6b66c14d507126c9d73b99 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 27 Sep 2023 19:21:49 -0700 Subject: [PATCH 07/12] Update documentation to be more descriptive --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66a70c4..45de849 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,10 @@ under mycroft.conf // "file_server_port": 8000, // Optional support for collecting GUI files for container support - // This example describes a configuration where the HOST system has collected - // GUI resources at `/tmp/gui_files`. The container path for these files will be - // {XDG_CACHE_HOME}/ovos_gui_file_server + // The ovos-gui container path for these files will be {XDG_CACHE_HOME}/ovos_gui_file_server. + // With the below configuration, the GUI client will have files prefixed with the configured host path, + // so the example below describes a situation where `{XDG_CACHE_HOME}/ovos_gui_file_server` maps + // to `/tmp/gui_files` on the filesystem where the GUI client is running. // "gui_file_host_path": "/tmp/gui_files", // Optionally specify a default qt version for connected clients that don't report it From af46fec8427a4458e36aa1ecccb430547b0991b0 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 28 Sep 2023 13:58:00 -0700 Subject: [PATCH 08/12] Fix check for GUI page upload --- ovos_gui/namespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 525a358..01eca37 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -512,7 +512,7 @@ def handle_gui_pages_available(self, message: Message): GUI framework. @param message: `gui.volunteer_page_upload` message """ - if not self.gui_file_path and not self.gui_file_server: + if not any((self.gui_file_host_path, self.gui_file_server)): LOG.debug("No GUI file server running or host path configured") return From b30c0cdb3a3f4128391ed823b8a729809daa5eff Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 28 Sep 2023 14:22:09 -0700 Subject: [PATCH 09/12] Troubleshooting page upload without http server --- ovos_gui/namespace.py | 10 ++++++++-- test/unittests/test_namespace.py | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 01eca37..2fc86cf 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -49,7 +49,7 @@ from ovos_bus_client import Message, MessageBusClient from ovos_config.config import Configuration -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation from ovos_gui.bus import ( create_gui_service, @@ -476,8 +476,14 @@ def _init_gui_file_share(self): """ config = Configuration().get("gui", {}) self.gui_file_host_path = config.get("gui_file_host_path") - if config.get("gui_file_server") or self.gui_file_path: + + # Check for GUI file sharing via HTTP server or mounted host path + if config.get("gui_file_server") or self.gui_file_host_path: from ovos_utils.xdg_utils import xdg_cache_home + if config.get("server_path"): + log_deprecation("`server_path` configuration is deprecated. " + "Files will always be saved to " + "XDG_CACHE_HOME/ovos_gui_file_server", "0.1.0") self.gui_file_path = config.get("server_path") or \ join(xdg_cache_home(), "ovos_gui_file_server") if config.get("gui_file_server"): diff --git a/test/unittests/test_namespace.py b/test/unittests/test_namespace.py index 8a3fec6..44e5055 100644 --- a/test/unittests/test_namespace.py +++ b/test/unittests/test_namespace.py @@ -44,6 +44,10 @@ class TestNamespace(TestCase): def setUp(self): self.namespace = Namespace("foo") + def test_init_gui_file_share(self): + # TODO: Test init with/without server and host config + pass + def test_add(self): add_namespace_message = dict( type="mycroft.session.list.insert", From 76ddbaf2de0635b11d61ee26357f17ec2f829345 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 28 Sep 2023 14:27:39 -0700 Subject: [PATCH 10/12] Troubleshooting page upload without http server (request upload) --- ovos_gui/namespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 2fc86cf..7373897 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -926,7 +926,7 @@ def handle_client_connected(self, message: Message): dict(port=port, gui_id=gui_id)) self.core_bus.emit(message) - if self.gui_file_path: + if self.gui_file_path or self.gui_file_host_path: if not self._ready_event.wait(90): LOG.warning("Not reported ready after 90s") if framework not in self._connected_frameworks: From 2ee74f34d917bf3465d85984893c496b0fb0b3fa Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 28 Sep 2023 14:40:32 -0700 Subject: [PATCH 11/12] Add debug logging --- ovos_gui/namespace.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 7373897..3cde48f 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -930,12 +930,14 @@ def handle_client_connected(self, message: Message): if not self._ready_event.wait(90): LOG.warning("Not reported ready after 90s") if framework not in self._connected_frameworks: + LOG.debug(f"Requesting page upload for {framework}") self.core_bus.emit(Message("gui.request_page_upload", {'framework': framework}, {"source": "gui", "destination": ["skills", "PHAL"]})) if framework not in self._connected_frameworks: + LOG.debug(f"Connecting framework: {framework}") self._connected_frameworks.append(framework) def handle_page_interaction(self, message: Message): From 7a96e82972f0ec3a12b0deff311ed6736819713d Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 28 Sep 2023 14:55:55 -0700 Subject: [PATCH 12/12] Handle schema for locally mapped GUI files with unit test --- ovos_gui/page.py | 8 ++++++-- test/unittests/test_page.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ovos_gui/page.py b/ovos_gui/page.py index 3bbb7ce..641f867 100644 --- a/ovos_gui/page.py +++ b/ovos_gui/page.py @@ -63,8 +63,12 @@ def get_uri(self, framework: str = "qt5", server_url: str = None) -> str: self.namespace if server_url: if "://" not in server_url: - LOG.debug(f"No schema in server_url, assuming 'http'") - server_url = f"http://{server_url}" + if server_url.startswith("/"): + LOG.debug(f"No schema in server_url, assuming 'file'") + server_url = f"file://{server_url}" + else: + LOG.debug(f"No schema in server_url, assuming 'http'") + server_url = f"http://{server_url}" path = f"{server_url}/{res_namespace}/{framework}/{res_filename}" LOG.info(f"Resolved server URI: {path}") return path diff --git a/test/unittests/test_page.py b/test/unittests/test_page.py index 366c923..b7756c9 100644 --- a/test/unittests/test_page.py +++ b/test/unittests/test_page.py @@ -36,6 +36,22 @@ def test_gui_page_from_server(self): self.assertEqual(qt6, f"https://files.local/{namespace}/qt5/{page_id}.qml") + def test_gui_page_from_mapped_path(self): + name = "test_page" + persistent = False + duration = 60 + page_id = "test_page" + namespace = "skill.test" + + page = GuiPage(None, name, persistent, duration, page_id, namespace) + qt5 = page.get_uri(server_url="/path/for/gui/client") + self.assertEqual(qt5, + f"file:///path/for/gui/client/{namespace}/qt5/{page_id}.qml") + + qt6 = page.get_uri(server_url="/path/for/gui/client") + self.assertEqual(qt6, + f"file:///path/for/gui/client/{namespace}/qt5/{page_id}.qml") + def test_gui_page_from_local_path(self): name = "test" persistent = True