Skip to content

Documentation for ToMeDa

tomeda.main

Main entry point for the tomeda package.

logger module-attribute

logger: TraceLogger = getLogger(__name__)

load_dataset_class

load_dataset_class(
    module: str, class_name: str
) -> type[pydantic.BaseModel]

Load a pydantic dataset class from a module.

Parameters:

Name Type Description Default
module str

Path to the module containing the dataset class.

required
class_name str

Name of the dataset class.

required

Returns:

Type Description
type[BaseModel]

The dataset class.

Source code in tomeda/main.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def load_dataset_class(
    module: str, class_name: str
) -> type[pydantic.BaseModel]:
    """
    Load a pydantic dataset class from a module.

    Parameters
    ----------
    module
        Path to the module containing the dataset class.
    class_name
        Name of the dataset class.

    Returns
    -------
    type[pydantic.BaseModel]
        The dataset class.
    """
    file_dir = os.path.dirname(module)
    sys.path.append(file_dir)
    module_name = os.path.basename(module)
    module_name = os.path.splitext(module_name)[0]
    module_type = importlib.import_module(module_name)
    dataset: type[pydantic.BaseModel] = getattr(module_type, class_name)
    return dataset

main

main() -> None
Source code in tomeda/main.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def main() -> None:
    param = get_parameters()

    # Create Schema Documentation
    if param.create_schema_documentation:
        logger.info("Creating schema documentation.")
        dataset_schema = load_dataset_class(
            param.schema_module, param.schema_class
        )
        dataset = TomedaBaseClass(dataset_schema, param)
        schema = json.dumps(dataset.root.schema())
        generate_pdf_from_schema(schema, param.output)

    # DOFF_01: Create Gatherer File
    if param.create_gatherer:
        logger.info("Creating gatherer file.")
        dataset_schema = load_dataset_class(
            param.schema_module, param.schema_class
        )
        dataset = TomedaBaseClass(dataset_schema, param)
        dataset.create_gatherer_file_nested_text(output_file=param.output)

    # DOFF_02: Create Dataset Table
    if param.create_dataset_table:
        logger.info("Creating dataset table.")
        dataset_schema = load_dataset_class(
            param.schema_module, param.schema_class
        )
        dataset = TomedaBaseClass(dataset_schema, param)
        dataset.create_info_table(output_file=param.output)

    # DOFF_03: Extract Dataverse Native Keys
    if param.extract_repository_metadata:
        logger.info("Extracting Dataverse native keys.")
        t10_extract_dataverse_native_keys.main(param)

    # DOFF_04: Derive Dataverse Keys
    if param.derive_repository_keys:
        logger.info("Deriving Dataverse keys.")
        t101_derive_dataverse_key.main(param)

    # DOFF_05: Derive Dataverse TSV from Mapping
    if param.derive_repository_tsv_from_mapping:
        logger.info("Deriving Dataverse TSV from mapping.")
        t11_create_dataverse_tsv_from_mapping.main(param)

    # USER_01: Read Gatherer File
    if param.read:
        logger.info("Reading gatherer file.")
        dataset_schema = load_dataset_class(
            param.schema_module, param.schema_class
        )
        dataset = TomedaBaseClass(dataset_schema, param)
        t01_gather_metadata.main(dataset, param)

    # USER_02: Create Dataverse Compatible JSON
    if param.create_repository_compatible_metadata:
        logger.info("Creating data repository compatible metadata.")
        t12_create_dataverse_compatible_json.main(param)

    # USER_03: Upload to Dataverse
    if param.upload:
        logger.info("Uploading to data repository.")
        t02_upload_to_dataverse.main(param)