Beispiel #1
0
def export_workspace(source_path, target_path, fmt, is_overwrite):
    if os.path.exists(target_path) and not is_overwrite:
        raise LocalFileExistsException()
    workspace_client = get_workspace_client()
    output = workspace_client.export_workspace(source_path, fmt)
    content = output['content']
    # Will overwrite target_path.
    with open(target_path, 'wb') as f:
        decoded = b64decode(content)
        f.write(decoded)
Beispiel #2
0
 def export_workspace(self, source_path, target_path, fmt, is_overwrite, headers=None):
     """
     Faithfully exports the source_path to the target_path. Does not
     attempt to do any munging of the target_path if it is a directory.
     """
     if os.path.exists(target_path) and not is_overwrite:
         raise LocalFileExistsException('Target {} already exists.'.format(target_path))
     output = self.client.export_workspace(source_path, fmt, headers=headers)
     content = output['content']
     # Will overwrite target_path.
     with open(target_path, 'wb') as f:
         decoded = b64decode(content)
         f.write(decoded)
Beispiel #3
0
 def get_file(self, dbfs_path, dst_path, overwrite, headers=None):
     if os.path.exists(dst_path) and not overwrite:
         raise LocalFileExistsException('{} exists already.'.format(dst_path))
     file_info = self.get_status(dbfs_path, headers=headers)
     if file_info.is_dir:
         error_and_quit(('The dbfs file {} is a directory.').format(repr(dbfs_path)))
     length = file_info.file_size
     offset = 0
     with open(dst_path, 'wb') as local_file:
         while offset < length:
             response = self.read(dbfs_path, offset, headers=headers)
             bytes_read = response['bytes_read']
             data = response['data']
             offset += bytes_read
             local_file.write(b64decode(data))
Beispiel #4
0
def get_file(dbfs_path, dst_path, overwrite):
    if os.path.exists(dst_path) and not overwrite:
        raise LocalFileExistsException()
    dbfs_api = get_dbfs_client()
    file_info = get_status(dbfs_path)
    if file_info.is_dir:
        error_and_quit(('The dbfs file {} is a directory.').format(repr(dbfs_path)))
    length = file_info.file_size
    offset = 0
    with open(dst_path, 'wb') as local_file:
        while offset < length:
            response = dbfs_api.read(dbfs_path.absolute_path, offset, BUFFER_SIZE_BYTES)
            bytes_read = response['bytes_read']
            data = response['data']
            offset += bytes_read
            local_file.write(b64decode(data))