From 17eeb667a14595b12ba927de1b945c7ab8e56824 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Fri, 30 Nov 2018 10:49:14 +0100 Subject: [PATCH 1/4] Hass.io: Show ANSI color codes in logs --- homeassistant/components/hassio/http.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index c3bd18fa9bbe89..5c8a3d8173383d 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -63,8 +63,6 @@ async def _handle(self, request, path): client = await self._command_proxy(path, request) data = await client.read() - if path.endswith('/logs'): - return _create_response_log(client, data) return _create_response(client, data) get = _handle @@ -114,18 +112,6 @@ def _create_response(client, data): ) -def _create_response_log(client, data): - """Convert a response from client request.""" - # Remove color codes - log = re.sub(r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))", "", data.decode()) - - return web.Response( - text=log, - status=client.status, - content_type=CONTENT_TYPE_TEXT_PLAIN, - ) - - def _get_timeout(path): """Return timeout for a URL path.""" if NO_TIMEOUT.match(path): From 2975f7c619ac4099a0e1b16465ecd4c9be2ef5dd Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 2 Dec 2018 10:43:53 +0100 Subject: [PATCH 2/4] Lint --- homeassistant/components/hassio/http.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index 5c8a3d8173383d..be2806716a7651 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -15,7 +15,6 @@ from aiohttp.hdrs import CONTENT_TYPE from aiohttp.web_exceptions import HTTPBadGateway -from homeassistant.const import CONTENT_TYPE_TEXT_PLAIN from homeassistant.components.http import KEY_AUTHENTICATED, HomeAssistantView from .const import X_HASSIO From 2b460b24a2ac46271f03a0ddc7361bf27893cfa6 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 2 Dec 2018 10:44:02 +0100 Subject: [PATCH 3/4] Fix test --- tests/components/hassio/test_http.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/components/hassio/test_http.py b/tests/components/hassio/test_http.py index 4370c011891b8e..ceb719e7ec0df1 100644 --- a/tests/components/hassio/test_http.py +++ b/tests/components/hassio/test_http.py @@ -102,15 +102,15 @@ def test_forward_request_no_auth_for_logo(hassio_client): @asyncio.coroutine def test_forward_log_request(hassio_client): - """Test fetching normal log path.""" + """Test fetching normal log path doesn't remove ANSI color escape codes.""" response = MagicMock() response.read.return_value = mock_coro('data') with patch('homeassistant.components.hassio.HassIOView._command_proxy', Mock(return_value=mock_coro(response))), \ - patch('homeassistant.components.hassio.http.' - '_create_response_log') as mresp: - mresp.return_value = 'response' + patch('homeassistant.components.hassio.http' + '._create_response') as mresp: + mresp.return_value = '\033[32mresponse\033[0m' resp = yield from hassio_client.get('/api/hassio/beer/logs', headers={ HTTP_HEADER_HA_AUTH: API_PASSWORD }) @@ -118,7 +118,7 @@ def test_forward_log_request(hassio_client): # Check we got right response assert resp.status == 200 body = yield from resp.text() - assert body == 'response' + assert body == '\033[32mresponse\033[0m' # Check we forwarded command assert len(mresp.mock_calls) == 1 From 5c07d62419a22871d4e7728113e725a85609093a Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 2 Dec 2018 10:48:24 +0100 Subject: [PATCH 4/4] Lint --- tests/components/hassio/test_http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/hassio/test_http.py b/tests/components/hassio/test_http.py index ceb719e7ec0df1..07db126312b0d1 100644 --- a/tests/components/hassio/test_http.py +++ b/tests/components/hassio/test_http.py @@ -108,8 +108,8 @@ def test_forward_log_request(hassio_client): with patch('homeassistant.components.hassio.HassIOView._command_proxy', Mock(return_value=mock_coro(response))), \ - patch('homeassistant.components.hassio.http' - '._create_response') as mresp: + patch('homeassistant.components.hassio.http.' + '_create_response') as mresp: mresp.return_value = '\033[32mresponse\033[0m' resp = yield from hassio_client.get('/api/hassio/beer/logs', headers={ HTTP_HEADER_HA_AUTH: API_PASSWORD