diff --git a/superset/cli.py b/superset/cli.py index 15a8ce9e14cfb..48044bcf6d1d3 100755 --- a/superset/cli.py +++ b/superset/cli.py @@ -34,6 +34,7 @@ from superset import app, appbuilder, config, security_manager from superset.app import create_app +from superset.examples.utils import load_from_configs from superset.extensions import celery_app, db from superset.utils import core as utils from superset.utils.celery import session_scope @@ -194,10 +195,18 @@ def load_examples( only_metadata: bool = False, force: bool = False, ) -> None: - """Loads a set of Slices and Dashboards and a supporting dataset """ + """Loads a set of Slices and Dashboards and a supporting dataset""" load_examples_run(load_test_data, load_big_data, only_metadata, force) +@with_appcontext +@superset.command() +@click.argument("directory") +def import_(directory: str) -> None: + """Imports configs from a given directory""" + load_from_configs(force_data=False, load_test_data=False, root=Path(directory)) + + @with_appcontext @superset.command() @click.option("--database_name", "-d", help="Database name to change") diff --git a/superset/examples/utils.py b/superset/examples/utils.py index 66ca811df2d35..66ce7d9384340 100644 --- a/superset/examples/utils.py +++ b/superset/examples/utils.py @@ -25,15 +25,18 @@ YAML_EXTENSIONS = {".yaml", ".yml"} -def load_from_configs(force_data: bool = False, load_test_data: bool = False) -> None: - contents = load_contents(load_test_data) +def load_from_configs( + force_data: bool = False, + load_test_data: bool = False, + root: Path = Path("examples/configs"), +) -> None: + contents = load_contents(root, load_test_data) command = ImportExamplesCommand(contents, overwrite=True, force_data=force_data) command.run() -def load_contents(load_test_data: bool = False) -> Dict[str, Any]: +def load_contents(root: Path, load_test_data: bool = False) -> Dict[str, Any]: """Traverse configs directory and load contents""" - root = Path("examples/configs") resource_names = resource_listdir("superset", str(root)) queue = [root / resource_name for resource_name in resource_names]