From 5cc09569ba8aaecd435989ed14802402ce6b032f Mon Sep 17 00:00:00 2001 From: Iakov Gan Date: Fri, 27 Dec 2024 13:05:37 +0100 Subject: [PATCH] get rid of click --- cid/common.py | 28 +++++++++++----------------- cid/helpers/quicksight/dashboard.py | 1 - 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/cid/common.py b/cid/common.py index 5640e5cb..acc6ad9c 100644 --- a/cid/common.py +++ b/cid/common.py @@ -3,6 +3,7 @@ import urllib import logging import functools +import webbrowser from string import Template from typing import Dict from pkg_resources import resource_string @@ -10,7 +11,6 @@ from functools import cached_property import yaml -import click import requests from botocore.exceptions import ClientError, NoCredentialsError, CredentialRetrievalError @@ -655,17 +655,15 @@ def open(self, dashboard_id, **kwargs): dashboard = self.qs.discover_dashboard(dashboard_id) - click.echo('Getting dashboard status...', nl=False) - if dashboard is not None: - if dashboard.version.get('Status') not in ['CREATION_SUCCESSFUL']: - print(json.dumps(dashboard.version.get('Errors'), - indent=4, sort_keys=True, default=str)) - click.echo( - f'\nDashboard is unhealthy, please check errors above.') - click.echo('healthy, opening...') - click.launch(self.qs_url.format(dashboard_id=dashboard_id, **self.qs_url_params)) - else: - click.echo('not deployed.') + logger.info('Getting dashboard status...') + if not dashboard: + logger.error(f'{dashboard_id} is not deployed.') + return None + if dashboard.version.get('Status') not in ['CREATION_SUCCESSFUL', 'UPDATE_IN_PROGRESS', 'UPDATE_SUCCESSFUL']: + cid_print(json.dumps(dashboard.version.get('Errors'), indent=4, sort_keys=True, default=str)) + cid_print(f'Dashboard {dashboard_id} is unhealthy, please check errors above.') + logger.info('healthy, opening...') + webbrowser.open(self.qs_url.format(dashboard_id=dashboard_id, **self.qs_url_params)) return dashboard_id @@ -724,11 +722,7 @@ def status(self, dashboard_id, **kwargs): logger.info(f'Updating dashboard: {dashboard.id} with Recursive = {recursive}') self._deploy(dashboard_id, recursive=recursive, update=True) logger.info('Rediscover dashboards after update') - - refresh_overrides = [ - dashboard.id - ] - self.qs.discover_dashboards(refresh_overrides = refresh_overrides) + self.qs.discover_dashboards(refresh_overrides=[dashboard.id]) self.qs.clear_dashboard_selection() dashboard_id = None else: diff --git a/cid/helpers/quicksight/dashboard.py b/cid/helpers/quicksight/dashboard.py index d6fea111..8a525554 100644 --- a/cid/helpers/quicksight/dashboard.py +++ b/cid/helpers/quicksight/dashboard.py @@ -4,7 +4,6 @@ from typing import Dict import yaml -import click from cid.helpers.quicksight.resource import CidQsResource from cid.helpers.quicksight.definition import Definition as CidQsDefinition