mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
* 7620: Start removing dependencies on requests * Patch urllib.request.urlopen instead of requests.get * Try to fix flake8 * More work on flake8 import errors * First attempt at using urllib with cookies * Fix pylint/flake8 * Fix test_deliver_slice_csv_attachment * Fix test_deliver_slice_csv_inline * Import requests and pydruid conditionally, remove dependency on prison * Fix flake errors * Fix load_examples * Please flake * Skip tests depending on optional deps * Try to please flake * Address review comments * Remove Druid-related UI * Revert "Remove Druid-related UI" This reverts commit d7e0f166cc3f3dd2496b4a666e177f0c191aeb0f. * Skip a few tests more * Put imports in right order * Apply black patch * Please flake * Please black, silence flake * Use flake8 silencing the right way * Add deps for CI
78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
"""Loads datasets, dashboards and slices in a new superset instance"""
|
|
# pylint: disable=C,R,W
|
|
from io import BytesIO
|
|
import json
|
|
import os
|
|
from urllib import request
|
|
import zlib
|
|
|
|
from superset import app, db
|
|
from superset.connectors.connector_registry import ConnectorRegistry
|
|
from superset.models import core as models
|
|
|
|
BASE_URL = "https://github.com/apache-superset/examples-data/blob/master/"
|
|
|
|
# Shortcuts
|
|
DB = models.Database
|
|
Slice = models.Slice
|
|
Dash = models.Dashboard
|
|
|
|
TBL = ConnectorRegistry.sources["table"]
|
|
|
|
config = app.config
|
|
|
|
EXAMPLES_FOLDER = os.path.join(config.get("BASE_DIR"), "examples")
|
|
|
|
misc_dash_slices = set() # slices assembled in a 'Misc Chart' dashboard
|
|
|
|
|
|
def update_slice_ids(layout_dict, slices):
|
|
charts = [
|
|
component
|
|
for component in layout_dict.values()
|
|
if isinstance(component, dict) and component["type"] == "CHART"
|
|
]
|
|
sorted_charts = sorted(charts, key=lambda k: k["meta"]["chartId"])
|
|
for i, chart_component in enumerate(sorted_charts):
|
|
if i < len(slices):
|
|
chart_component["meta"]["chartId"] = int(slices[i].id)
|
|
|
|
|
|
def merge_slice(slc):
|
|
o = db.session.query(Slice).filter_by(slice_name=slc.slice_name).first()
|
|
if o:
|
|
db.session.delete(o)
|
|
db.session.add(slc)
|
|
db.session.commit()
|
|
|
|
|
|
def get_slice_json(defaults, **kwargs):
|
|
d = defaults.copy()
|
|
d.update(kwargs)
|
|
return json.dumps(d, indent=4, sort_keys=True)
|
|
|
|
|
|
def get_example_data(filepath, is_gzip=True, make_bytes=False):
|
|
content = request.urlopen(f"{BASE_URL}{filepath}?raw=true").read()
|
|
if is_gzip:
|
|
content = zlib.decompress(content, zlib.MAX_WBITS | 16)
|
|
if make_bytes:
|
|
content = BytesIO(content)
|
|
return content
|