Source code for kvalikirstu2.data_archive_interface

""" A module for the DataArchiveInterface base class.
"""
import re


[docs]class MetadataInformation: """ A data container class for study metadata. """ def __init__(self, study_id, citation_requirement, title): self.study_id = study_id self.citation_requirement = citation_requirement self.title = title
[docs] def extract_study_number(self): """Extracts the study number out of the study_id. Assumes first 3 characters should be excluded. """ match = re.search(r'\d', self.study_id) if match: return self.study_id[match.start():] return ''
[docs]class Command: """A command that can be issued via the GUI. :var text: The label of the command. :var help_text: The help text associated with the command. """ def __init__(self, func, text, help_text): self._func = func self.text = text self.help_text = help_text
[docs] def execute(self): """Executes the command. """ self._func()
[docs]class DataArchiveInterface: """An abstract baseclass to isolate any FSD specific functionality out of the main program. """
[docs] def parse_study_information(self, study_path, data_path): """Parses study metadata from given path. :param study_path: The path of the study folder. :param data_path: The path of the data folder. :rtype: MetadataInformation """ raise NotImplementedError()
[docs] def rename_data_files_in_folder(self, metadata: MetadataInformation, data_path: str): """ Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc. :param metadata: The metadata of the study. :param str data_path: The path of the data folder. """ raise NotImplementedError()
[docs] def add_cli_arguments(self, argument_parser): """Add CLI arguments based on the needs of the data repository. :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ raise NotImplementedError()
[docs] def add_gui_arguments(self, argument_parser): """Add GUI arguments based on the needs of the data repository. :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ raise NotImplementedError()
[docs] def add_shared_arguments(self, argument_parser): """Add shared arguments based on the needs of the data repository. Shared means it's used for both the CLI and GUI :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ raise NotImplementedError()
[docs] def get_study_data_filename(self, metadata: MetadataInformation): """Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable. :param MetadataInformation metadata: The metadata of the study. """ raise NotImplementedError()
[docs] def create_csv_name(self, metadata: MetadataInformation): """Returns the name of the .csv file for the study with the given ID. :param MetadataInformation metadata: The metadata of the study. """ raise NotImplementedError()
[docs] def get_metadata_files(self, study_path, data_path): """Returns a list of files that are metadata files of the study in the data folder. :param str study_path: The path of the study. :param str data_path: The path of the data folder. """ raise NotImplementedError()
[docs] def get_commands(self): """Returns a list of commands that can be executed from the GUI. :return: A list of commands. """ return []
[docs]class DummyInterface(DataArchiveInterface): """An dummy class to implement basic functionality so that the program can work. """
[docs] def parse_study_information(self, study_path, data_path): """Parses study metadata from given path. :param study_path: The path of the study folder. :param data_path: The path of the data folder. :rtype: MetadataInformation """ return MetadataInformation('study_id', 'citreq', 'title')
# pylint: disable=unnecessary-pass
[docs] def rename_data_files_in_folder(self, metadata: MetadataInformation, data_path: str): """ Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc. :param metadata: The metadata of the study. :param str data_path: The path of the data folder. """ pass
[docs] def add_cli_arguments(self, argument_parser): """Add CLI arguments based on the needs of the data repository. :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ pass
[docs] def add_gui_arguments(self, argument_parser): """Add GUI arguments based on the needs of the data repository. :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ pass
[docs] def add_shared_arguments(self, argument_parser): """Add shared arguments based on the needs of the data archive. Shared means it's used for both the CLI and GUI :param Kvalikirstu2ConfigArgParser argument_parser: The argument parser. """ pass
# pylint: enable=unnecessary-pass
[docs] def get_study_data_filename(self, metadata: MetadataInformation): """Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable. :param MetadataInformation metadata: The metadata of the study. """ return "%s.txt" % metadata.study_id
[docs] def create_csv_name(self, metadata: MetadataInformation): """Returns the name of the .csv file for the study with the given ID. :param MetadataInformation metadata: The metadata of the study. """ return "%s.csv" % metadata.study_id
[docs] def get_metadata_files(self, study_path, data_path): """Returns a list of files that are metadata files of the study in the data folder. :param str study_path: The path of the study. :param str data_path: The path of the data folder. """ return []