Exemplo n.º 1
0
def export_workspace_cli(api_client, source_path, target_path, format, overwrite): # NOQA
    """
    Exports a notebook from the Databricks workspace.

    The format is by default SOURCE. Possible formats are SOURCE, HTML, JUPTYER, and DBC. Each
    format is documented at
    https://docs.databricks.com/api/latest/workspace.html#notebookexportformat.
    """
    if os.path.isdir(target_path):
        file_info = WorkspaceApi(api_client).get_status(source_path)
        if not file_info.is_notebook:
            raise RuntimeError('Export can only be called on a notebook.')
        extension = WorkspaceLanguage.to_extension(file_info.language)
        target_path = os.path.join(target_path, file_info.basename + extension)
    WorkspaceApi(api_client).export_workspace(source_path, target_path, format, overwrite) # NOQA
Exemplo n.º 2
0
def mkdirs_cli(api_client, workspace_path):
    """
    Make directories in the Databricks Workspace.

    Mkdirs will create directories along the path to the argument directory.
    """
    WorkspaceApi(api_client).mkdirs(workspace_path)
Exemplo n.º 3
0
def delete_cli(api_client, workspace_path, recursive):
    """
    Deletes objects from the Databricks workspace.

    To delete a folder add the recursive flag.
    """
    WorkspaceApi(api_client).delete(workspace_path, recursive)
Exemplo n.º 4
0
def import_workspace_cli(api_client, source_path, target_path, language, format, overwrite): # NOQA
    """
    Imports a file from local to the Databricks workspace.

    The format is by default SOURCE. Possible formats are SOURCE, HTML, JUPTYER, and DBC. Each
    format is documented at
    https://docs.databricks.com/api/latest/workspace.html#notebookexportformat.
    """
    WorkspaceApi(api_client).import_workspace(source_path, target_path, language, format, overwrite) # NOQA
Exemplo n.º 5
0
def import_dir_cli(api_client, source_path, target_path, overwrite, exclude_hidden_files):
    """
    Recursively imports a directory from local to the Databricks workspace.

    Only directories and files with the extensions .scala, .py, .sql, .r, .R, .ipynb are imported.
    When imported, these extensions will be stripped off the name of the notebook.
    """
    _import_dir_helper(WorkspaceApi(api_client), source_path, target_path, overwrite,
                       exclude_hidden_files)
Exemplo n.º 6
0
def export_dir_cli(api_client, source_path, target_path, overwrite):
    """
    Recursively exports a directory from the Databricks workspace.

    Only directories and notebooks are exported. Notebooks are always exported in the SOURCE
    format. Notebooks will also have the extension of .scala, .py, .sql, or .r appended
    depending on the language type.
    """
    workspace_api = WorkspaceApi(api_client)
    assert workspace_api.get_status(source_path).is_dir, 'The source path must be a directory. {}' \
        .format(source_path)
    _export_dir_helper(workspace_api, source_path, target_path, overwrite)
Exemplo n.º 7
0
def ls_cli(api_client, l, absolute, workspace_path):
    """
    List objects in the Databricks Workspace.
    """
    if len(workspace_path) == 0:
        workspace_path = '/'
    else:
        workspace_path = workspace_path[0]
    objects = WorkspaceApi(api_client).list_objects(workspace_path)
    table = tabulate([obj.to_row(is_long_form=l, is_absolute=absolute) for obj in objects],
                     tablefmt='plain')
    click.echo(table)
Exemplo n.º 8
0
def ls_cli(api_client, is_long_form, with_object_id, absolute,
           workspace_path):  # noqa
    """
    List objects in the Databricks Workspace.
    """
    if len(workspace_path) == 0:
        workspace_path = '/'
    else:
        workspace_path = workspace_path[0]
    objects = WorkspaceApi(api_client).list_objects(workspace_path)
    objects_table = [
        obj.to_row(is_long_form=is_long_form,
                   is_absolute=absolute,
                   with_object_id=with_object_id) for obj in objects
    ]
    table = tabulate(objects_table, tablefmt='plain')
    click.echo(table)
Exemplo n.º 9
0
def pull(api_client, folder, verbose):
    """
    Pull notebooks from Databricks into a local git repo.
    """
    local_folder, remote_folder = _get_local_and_remote_folders(folder)
    workspace = WorkspaceApi(api_client)

    def work():
        workspace.export_workspace_dir(remote_folder,
                                       local_folder,
                                       True,
                                       verbose=verbose)

    if not verbose:
        with loadingbar(msg="Pulling from {}".format(remote_folder),
                        width=10,
                        fill_char="o",
                        interval=.25):
            work()
    else:
        work()
Exemplo n.º 10
0
 def __init__(self, api_client):
     self.jobs_client = JobsApi(api_client)
     self.workspace_client = WorkspaceApi(api_client)
     self.dbfs_client = DbfsApi(api_client)
Exemplo n.º 11
0
def tgt_workspace_api(tgt_api_client:ApiClient):
    return WorkspaceApi(tgt_api_client)
Exemplo n.º 12
0
def src_workspace_api(src_api_client:ApiClient):
    return WorkspaceApi(src_api_client)