7
7
from abc import ABCMeta , abstractmethod
8
8
from typing import Union
9
9
from io import BytesIO
10
- from dwcahandler .dwca import CoreOrExtType , CsvFileType , MetaElementTypes
10
+ from dwcahandler .dwca import CoreOrExtType , ContentData , MetaElementTypes
11
11
from dwcahandler .dwca .eml import Eml
12
12
13
13
14
14
class BaseDwca (metaclass = ABCMeta ):
15
15
"""An abstract DwCA that provides basic operations"""
16
16
17
17
@abstractmethod
18
- def extract_csv_content (self , csv_info : CsvFileType , core_ext_type : CoreOrExtType ,
18
+ def extract_csv_content (self , csv_info : ContentData , core_ext_type : CoreOrExtType ,
19
19
build_coreid_for_ext : bool = False ):
20
20
"""Get the content from a single file in the DwCA
21
21
@@ -48,11 +48,11 @@ def generate_meta(self):
48
48
49
49
@abstractmethod
50
50
def write_dwca (self , output_dwca : Union [str , BytesIO ]):
51
- """Write the content of the DwCA to a directory .
51
+ """Write the content of the DwCA to a file path (supplied as string) or to BytesIO in memory .
52
52
53
- Writes all CSV files , as well as a meta-file and EML file for the archive.
53
+ Writes all CSV data , as well as a meta-file and EML file for the archive.
54
54
55
- :param output_dwca: The path to write to or dwca in memory
55
+ :param output_dwca: The file path or BytesIO
56
56
"""
57
57
pass
58
58
@@ -85,7 +85,7 @@ def convert_associated_media_to_extension(self):
85
85
pass
86
86
87
87
@abstractmethod
88
- def delete_records (self , records_to_delete : CsvFileType ):
88
+ def delete_records (self , records_to_delete : ContentData ):
89
89
pass
90
90
91
91
@abstractmethod
@@ -111,10 +111,10 @@ def fill_additional_info(self):
111
111
for multimedia_content , _ in contents :
112
112
self .add_multimedia_info_to_content (multimedia_content )
113
113
114
- def delete_records_in_dwca (self , records_to_delete : CsvFileType , output_dwca : Union [str , BytesIO ]):
115
- """Delete records in dwca if the key records are defined in CsvFileType
114
+ def delete_records_in_dwca (self , records_to_delete : ContentData , output_dwca : Union [str , BytesIO ]):
115
+ """Delete records in dwca if the key records are defined in ContentData
116
116
117
- :param records_to_delete: A CsvFileType that containing the text file of the record keys,
117
+ :param records_to_delete: A ContentData that containing the text file of the record keys,
118
118
the key names of the records and MetaElementType type class of the dwca
119
119
where the records need to be removed
120
120
:param output_dwca: output dwca path where the result of the dwca is writen to or the output dwca in memory
@@ -125,14 +125,14 @@ def delete_records_in_dwca(self, records_to_delete: CsvFileType, output_dwca: Un
125
125
self .generate_meta ()
126
126
self .write_dwca (output_dwca )
127
127
128
- def create_dwca (self , core_csv : CsvFileType , output_dwca : Union [str , BytesIO ],
129
- ext_csv_list : list [CsvFileType ] = None , validate_content : bool = True ,
128
+ def create_dwca (self , core_csv : ContentData , output_dwca : Union [str , BytesIO ],
129
+ ext_csv_list : list [ContentData ] = None , validate_content : bool = True ,
130
130
eml_content : Union [str , Eml ] = '' ):
131
131
"""Create a dwca given the contents of core and extensions and eml content
132
132
133
- :param core_csv: CsvFileType containing the files , class types and keys to form the core of the dwca
133
+ :param core_csv: ContentData containing the data , class type and keys to form the core of the dwca
134
134
:param output_dwca: the resulting path of the dwca or the dwca in memory
135
- :param ext_csv_list: list of CsvFileTypes containing the files , class types and keys to form the
135
+ :param ext_csv_list: list of ContentData containing the data , class type and keys to form the
136
136
extensions of the dwca if supplied
137
137
:param validate_content: whether to validate the contents
138
138
:param eml_content: eml content in string or a filled Eml object
@@ -143,7 +143,7 @@ def create_dwca(self, core_csv: CsvFileType, output_dwca: Union[str, BytesIO],
143
143
self .extract_csv_content (csv_info = core_csv , core_ext_type = CoreOrExtType .CORE ,
144
144
build_coreid_for_ext = True if len (ext_csv_list ) > 0 else False )
145
145
146
- # if multimedia files is supplied, do not attempt to convert associated media to multimedia
146
+ # if multimedia data is supplied, do not attempt to convert associated media to multimedia
147
147
if not any (ext .type == MetaElementTypes .MULTIMEDIA for ext in ext_csv_list ):
148
148
image_ext = self .convert_associated_media_to_extension ()
149
149
if image_ext :
@@ -200,10 +200,10 @@ def validate_dwca(self, content_keys: dict, error_file: str):
200
200
set_keys = self .set_keys (content_keys )
201
201
return self .validate_content (content_to_validate = set_keys , error_file = error_file )
202
202
203
- def validate_file (self , csv : CsvFileType , error_file : str ):
203
+ def validate_file (self , csv : ContentData , error_file : str ):
204
204
"""Validate the text file
205
205
206
- :param csv: CsvFileType to pass the csv, key and type
206
+ :param csv: ContentData to pass the csv, key and type
207
207
:param error_file: optional error_file for the errored data
208
208
"""
209
209
self .extract_csv_content (csv_info = csv , core_ext_type = CoreOrExtType .CORE )
0 commit comments