Source code for kvalikirstu2.data_archive_interface
""" A module for the DataArchiveInterface base class.
"""
import re
[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 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_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.
"""
# 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