forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import/export dashboards via cli (apache#6061)
* feat: import/export dashboards via cli * style: fixed lint error * test: added test for import and export util * test: removing import test as it is causing integrity issues Import is a wrapper around exist functionality so we can go ahead without a test or mock the actual db operation using https://docs.python.org/3/library/unittest.mock.html And validate the wrapper operations only. * test: remove test data file * test: removed usage of reserved keyword id * Fix: remove test that is causing unintended impact
- Loading branch information
1 parent
6d9bd31
commit 3af0cec
Showing
3 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=C,R,W | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import json | ||
import logging | ||
import time | ||
|
||
from superset import utils | ||
from superset.models.core import Dashboard | ||
|
||
|
||
def import_dashboards(session, data_stream, import_time=None): | ||
"""Imports dashboards from a stream to databases""" | ||
current_tt = int(time.time()) | ||
import_time = current_tt if import_time is None else import_time | ||
data = json.loads(data_stream.read(), object_hook=utils.decode_dashboards) | ||
# TODO: import DRUID datasources | ||
for table in data['datasources']: | ||
type(table).import_obj(table, import_time=import_time) | ||
session.commit() | ||
for dashboard in data['dashboards']: | ||
Dashboard.import_obj( | ||
dashboard, import_time=import_time) | ||
session.commit() | ||
|
||
|
||
def export_dashboards(session): | ||
"""Returns all dashboards metadata as a json dump""" | ||
logging.info('Starting export') | ||
dashboards = session.query(Dashboard) | ||
dashboard_ids = [] | ||
for dashboard in dashboards: | ||
dashboard_ids.append(dashboard.id) | ||
data = Dashboard.export_dashboards(dashboard_ids) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters