def import_dashboards(path, recursive): """Import dashboards from JSON""" p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob("*.json")) elif p.exists() and recursive: files.extend(p.rglob("*.json")) for f in files: logging.info("Importing dashboard from file %s", f) try: with f.open() as data_stream: dashboard_import_export.import_dashboards(db.session, data_stream) except Exception as e: logging.error("Error when importing dashboard from file %s", f) logging.error(e)
def import_dashboards(path, recursive=False): """Import dashboards from JSON""" p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.json')) elif p.exists() and recursive: files.extend(p.rglob('*.json')) for f in files: logging.info('Importing dashboard from file %s', f) try: with f.open() as data_stream: dashboard_import_export.import_dashboards( db.session, data_stream) except Exception as e: logging.error('Error when importing dashboard from file %s', f) logging.error(e)
def import_dashboards(path, recursive, username): """Import dashboards from JSON""" p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.json')) elif p.exists() and recursive: files.extend(p.rglob('*.json')) if username is not None: g.user = security_manager.find_user(username=username) for f in files: logging.info('Importing dashboard from file %s', f) try: with f.open() as data_stream: dashboard_import_export.import_dashboards( db.session, data_stream) except Exception as e: logging.error('Error when importing dashboard from file %s', f) logging.error(e)
def import_dashboards(path: str, recursive: bool, username: str) -> None: """Import dashboards from JSON""" from superset.utils import dashboard_import_export path_object = Path(path) files = [] if path_object.is_file(): files.append(path_object) elif path_object.exists() and not recursive: files.extend(path_object.glob("*.json")) elif path_object.exists() and recursive: files.extend(path_object.rglob("*.json")) if username is not None: g.user = security_manager.find_user(username=username) for file_ in files: logger.info("Importing dashboard from file %s", file_) try: with file_.open() as data_stream: dashboard_import_export.import_dashboards(data_stream) except Exception as ex: # pylint: disable=broad-except logger.error("Error when importing dashboard from file %s", file_) logger.error(ex)
def import_dashboard(path): print('Importing dashboard from file %s', path) with open(path) as data_stream: dashboard_import_export.import_dashboards(db.session, data_stream)