Пример #1
0
 def export_workspace_dir(self,
                          source_path,
                          target_path,
                          format=WorkspaceFormat.SOURCE,
                          overwrite):
     if os.path.isfile(target_path):
         click.echo('{} exists as a file. Skipping this subtree {}'.format(
             target_path, source_path))
         return
     if not os.path.isdir(target_path):
         os.makedirs(target_path)
     for obj in self.list_objects(source_path):
         cur_src = obj.path
         cur_dst = os.path.join(target_path, obj.basename)
         if obj.is_dir:
             self.export_workspace_dir(cur_src, cur_dst, overwrite)
         elif obj.is_notebook:
             cur_dst = cur_dst + WorkspaceLanguage.to_extension(
                 obj.language)
             try:
                 self.export_workspace(cur_src, cur_dst, format, overwrite)
                 click.echo('{} -> {}'.format(cur_src, cur_dst))
             except LocalFileExistsException:
                 click.echo('{} already exists locally as {}. Skip.'.format(
                     cur_src, cur_dst))
         else:
             click.echo(
                 '{} is neither a dir or a notebook. Skip.'.format(cur_src))
Пример #2
0
def export_workspace_cli(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 = 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)
    export_workspace(source_path, target_path, format, overwrite) # NOQA
Пример #3
0
 def export_workspace_dir(self,
                          source_path,
                          target_path,
                          overwrite,
                          headers=None):
     os_compatible_target_path = re.sub(LOCAL_OS_COMPATIBLE_PATH_REGEX, '_',
                                        target_path)
     if os.path.isfile(os_compatible_target_path):
         click.echo('{} exists as a file. Skipping this subtree {}'.format(
             os_compatible_target_path, source_path))
         return
     if not os.path.isdir(os_compatible_target_path):
         os.makedirs(os_compatible_target_path)
     for obj in self.list_objects(source_path, headers=headers):
         cur_src = obj.path
         cur_dst = os.path.join(os_compatible_target_path, obj.basename)
         if obj.is_dir:
             self.export_workspace_dir(cur_src,
                                       cur_dst,
                                       overwrite,
                                       headers=headers)
         elif obj.is_notebook:
             cur_dst = cur_dst + WorkspaceLanguage.to_extension(
                 obj.language)
             try:
                 self.export_workspace(cur_src,
                                       cur_dst,
                                       WorkspaceFormat.SOURCE,
                                       overwrite,
                                       headers=headers)
                 click.echo('{} -> {}'.format(cur_src, cur_dst))
             except LocalFileExistsException:
                 click.echo('{} already exists locally as {}. Skip.'.format(
                     cur_src, cur_dst))
         else:
             click.echo(
                 '{} is neither a dir or a notebook. Skip.'.format(cur_src))