Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vrymar committed Oct 16, 2024
1 parent fd508ae commit 452fbf4
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions grafana_import/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def main():
if args.action == "exporter" and (
"dashboard_name" not in config["general"] or config["general"]["dashboard_name"] is None
):
logger.error("ERROR: no dashboard has been specified.")
logger.error("ERROR: no dashboard has been specified.")

Check warning on line 217 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L217

Added line #L217 was not covered by tests
sys.exit(1)

Expand All @@ -241,14 +240,12 @@ def main():
try:
grafana_api = Grafana.Grafana(**params)
except Exception as e:
logger.error(f"ERROR: {e}")
logger.error(f"ERROR: {e}")

Check warning on line 243 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L243

Added line #L243 was not covered by tests
sys.exit(1)

# Import
if args.action == "import":
if args.dashboard_file is None:
logger.error("ERROR: no file to import provided!")
logger.error("ERROR: no file to import provided!")

Check warning on line 249 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L249

Added line #L249 was not covered by tests
sys.exit(1)

Expand All @@ -257,8 +254,6 @@ def main():
import_file = args.dashboard_file
import_files = []

Check warning on line 255 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L255

Added line #L255 was not covered by tests

import_files = []

if not re.search(r"^(?:(?:/)|(?:\.?\./))", import_file):
import_path = base_path
if "import_path" in config["general"]:
Expand All @@ -283,9 +278,7 @@ def main():
def process_dashboard(file_path):

Check warning on line 278 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L278

Added line #L278 was not covered by tests
try:
dash = read_dashboard_file(file_path)

Check warning on line 280 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L280

Added line #L280 was not covered by tests
dash = read_dashboard_file(file_path)
except Exception as ex:
msg = f"Failed to load dashboard from: {file_path}. Reason: {ex}"
msg = f"Failed to load dashboard from: {file_path}. Reason: {ex}"

Check warning on line 282 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L282

Added line #L282 was not covered by tests
logger.exception(msg)
raise IOError(msg) from ex
Expand Down Expand Up @@ -326,22 +319,17 @@ def process_dashboard(file_path):
try:
grafana_api.remove_dashboard(dashboard_name)
logger.info(f"OK: Dashboard removed: {dashboard_name}")

Check warning on line 321 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L321

Added line #L321 was not covered by tests
logger.info(f"OK: Dashboard removed: {dashboard_name}")
sys.exit(0)
except Grafana.GrafanaDashboardNotFoundError as exp:
logger.info(f"KO: Dashboard not found in folder '{exp.folder}': {exp.dashboard}")
logger.info(f"KO: Dashboard not found in folder '{exp.folder}': {exp.dashboard}")

Check warning on line 324 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L324

Added line #L324 was not covered by tests
sys.exit(1)
except Grafana.GrafanaFolderNotFoundError as exp:
logger.info(f"KO: Folder not found: {exp.folder}")
logger.info(f"KO: Folder not found: {exp.folder}")

Check warning on line 327 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L327

Added line #L327 was not covered by tests
sys.exit(1)
except GrafanaApi.GrafanaBadInputError as exp:
logger.info(f"KO: Removing dashboard failed: {dashboard_name}. Reason: {exp}")
logger.info(f"KO: Removing dashboard failed: {dashboard_name}. Reason: {exp}")

Check warning on line 330 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L330

Added line #L330 was not covered by tests
sys.exit(1)
except Exception:
logger.info("ERROR: Dashboard '{0}' remove exception '{1}'".format(dashboard_name, traceback.format_exc()))
logger.info("ERROR: Dashboard '{0}' remove exception '{1}'".format(dashboard_name, traceback.format_exc()))

Check warning on line 333 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L333

Added line #L333 was not covered by tests
sys.exit(1)

Expand All @@ -351,11 +339,9 @@ def process_dashboard(file_path):
try:
dash = grafana_api.export_dashboard(dashboard_name)
except (Grafana.GrafanaFolderNotFoundError, Grafana.GrafanaDashboardNotFoundError):
logger.info("KO: Dashboard name not found: {0}".format(dashboard_name))
logger.info("KO: Dashboard name not found: {0}".format(dashboard_name))

Check warning on line 342 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L342

Added line #L342 was not covered by tests
sys.exit(1)
except Exception:
logger.info("ERROR: Dashboard '{0}' export exception '{1}'".format(dashboard_name, traceback.format_exc()))
logger.info("ERROR: Dashboard '{0}' export exception '{1}'".format(dashboard_name, traceback.format_exc()))

Check warning on line 345 in grafana_import/cli.py

View check run for this annotation

Codecov / codecov/patch

grafana_import/cli.py#L345

Added line #L345 was not covered by tests
sys.exit(1)

Expand Down

0 comments on commit 452fbf4

Please sign in to comment.