Beispiel #1
0
class TVBExporter(ABCExporter):
    """ 
    This exporter simply provides for download data in TVB format
    """
    def __init__(self):
        self.storage_interface = StorageInterface()

    def get_supported_types(self):
        return [DataType]

    def get_label(self):
        return "TVB Format"

    def export(self, data, project):
        """
        Exports data type:
        1. If data is a normal data type, simply exports storage file (HDF format)
        2. If data is a DataTypeGroup creates a zip with all files for all data types
        """
        download_file_name = self._get_export_file_name(data)

        if self.is_data_a_group(data):
            all_datatypes = self._get_all_data_types_arr(data)

            if all_datatypes is None or len(all_datatypes) == 0:
                raise ExportException(
                    "Could not export a data type group with no data")

            # Create ZIP archive
            zip_file = self.storage_interface.export_datatypes_structure(
                all_datatypes, data, download_file_name, project.name)

            return download_file_name, zip_file, True

        else:
            data_path = h5.path_for_stored_index(data)
            data_file = self.storage_interface.export_datatypes([data_path],
                                                                data, None)

            return None, data_file, True

    def get_export_file_extension(self, data):
        if self.is_data_a_group(data):
            return StorageInterface.TVB_ZIP_FILE_EXTENSION
        else:
            return StorageInterface.TVB_STORAGE_FILE_EXTENSION
Beispiel #2
0
class TVBExporter(ABCExporter):
    """ 
    This exporter simply provides for download data in TVB format
    """
    def __init__(self):
        self.storage_interface = StorageInterface()

    def get_supported_types(self):
        return [DataType]

    def get_label(self):
        return "TVB Format"

    def export(self, data, project, public_key_path, password):
        """
        Exports data type:
        1. If data is a normal data type, simply exports storage file (HDF format)
        2. If data is a DataTypeGroup creates a zip with all files for all data types
        """
        download_file_name = self._get_export_file_name(data)

        if DataTypeGroup.is_data_a_group(data):
            _, op_file_dict = self.prepare_datatypes_for_export(data)

            # Create ZIP archive
            zip_file = self.storage_interface.export_datatypes_structure(
                op_file_dict, data, download_file_name, public_key_path,
                password)
            return download_file_name, zip_file, True
        else:
            data_path = h5.path_for_stored_index(data)
            data_file = self.storage_interface.export_datatypes(
                [data_path], data, download_file_name, public_key_path,
                password)

            return None, data_file, True

    def get_export_file_extension(self, data):
        if DataTypeGroup.is_data_a_group(data):
            return StorageInterface.TVB_ZIP_FILE_EXTENSION
        else:
            return StorageInterface.TVB_STORAGE_FILE_EXTENSION
Beispiel #3
0
class TVBLinkedExporter(ABCExporter):
    """
    """
    def __init__(self):
        self.storage_interface = StorageInterface()

    def get_supported_types(self):
        return [DataType]

    def get_label(self):
        return "TVB Format with links"

    def gather_datatypes_for_copy(self, data, dt_path_list):
        data_path = h5.path_for_stored_index(data)

        if data_path not in dt_path_list:
            dt_path_list.append(data_path)

        with H5File.from_file(data_path) as f:
            sub_dt_refs = f.gather_references()

            for _, ref_gid in sub_dt_refs:
                if ref_gid:
                    dt = load.load_entity_by_gid(ref_gid)
                    self.gather_datatypes_for_copy(dt, dt_path_list)

    def export(self, data, project, public_key_path, password):
        """
        Exports data type:
        1. If data is a normal data type, simply exports storage file (HDF format)
        2. If data is a DataTypeGroup creates a zip with all files for all data types
        """
        download_file_name = self._get_export_file_name(data)
        if DataTypeGroup.is_data_a_group(data):
            all_datatypes, op_file_dict = self.prepare_datatypes_for_export(
                data)

            # Copy the linked datatypes
            dt_path_list = []
            data_type = all_datatypes[0]
            self.gather_datatypes_for_copy(data_type, dt_path_list)

            # Create ZIP archive
            zip_file = self.storage_interface.export_datatypes_structure(
                op_file_dict, data, download_file_name, public_key_path,
                password, (dt_path_list[1:], data_type))

            return download_file_name, zip_file, True
        else:
            dt_path_list = []
            self.gather_datatypes_for_copy(data, dt_path_list)

            download_file_name = self._get_export_file_name(data)
            zip_to_export = self.storage_interface.export_datatypes(
                dt_path_list, data, download_file_name, public_key_path,
                password)
            return None, zip_to_export, True

    def get_export_file_extension(self, data):
        return StorageInterface.TVB_ZIP_FILE_EXTENSION

    def skip_group_datatypes(self):
        return False