caosadvancedtools.table_export module#
Collect optional and mandatory data from LinkAhead records and prepare them for an export as a table, e.g., for the export to metadata repositories.
- class caosadvancedtools.table_export.BaseTableExporter(export_dict, record=None, raise_error_if_missing=False)#
Bases:
objectBase exporter class from which all actual implementations inherit. It contains the basic structure with a dictionary for optional and mandatory keys, and the error handling. The actual logic for finding the values to the entries has to be implemented elsewhere. The final results are stored in the info dict.
- collect_information()#
Use the items of export_dict to collect the information for the export.
- prepare_csv_export(delimiter=',', print_header=False, skip_empty_optionals=False)#
Return the values in self.info as a single-line string, separated by the delimiter. If header is true, a header line with the names of the entries, separated by the same delimiter is added. Header and body are separated by a newline character.
- Parameters:
delimiter (string, optional) – symbol that separates two consecutive entries, e.g. ‘,’ for .csv or ‘ ‘ for .tsv. Default is ‘,’.
print_header (bool, optional) – specify whether a header line with all entry names separated by the delimiter precedes the body. Default is False.
skip_empty_optionals (bool, True) – if this is true, optional entries without value will be skipped in the output string. Otherwise an empty field will be attached. Default is False.
- Raises:
TableExportError: – if mandatory entries are missing a value
- Returns:
a single string, either only the body line, or header and body separated by a newline character if header is True.
- Return type:
string
- exception caosadvancedtools.table_export.TableExportError(msg)#
Bases:
LinkAheadExceptionError that is raised in case of failing export, e.g., because of missing mandatory entries.