The ObjectCSVManager class¶
gamslib.objectcsv.objectcsvmanager.ObjectCSVManager
¶
Manage object and datastream metadata for a single GAMS object directory.
Stores, reads, writes, validates, and merges metadata for the object and its datastreams.
Initialize the ObjectCSVManager with the given object directory.
| PARAMETER | DESCRIPTION |
|---|---|
obj_dir
|
Path to the object directory.
TYPE:
|
ignore_existing_csv_files
|
If True, ignore existing CSV files when writing.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the object directory does not exist. |
InvalidCSVFileError
|
If the CSV files are malformed. |
set_object
¶
Set the object metadata.
| PARAMETER | DESCRIPTION |
|---|---|
object_data
|
Object metadata to set.
TYPE:
|
replace
|
If True, replace existing object data.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If object data is already set and replace is False. |
merge_object
¶
Merge the object metadata with another ObjectData object.
| PARAMETER | DESCRIPTION |
|---|---|
object_data
|
Object metadata to merge.
TYPE:
|
get_object
¶
Return the object metadata.
| RETURNS | DESCRIPTION |
|---|---|
ObjectData
|
The object metadata, or None if not set.
TYPE:
|
add_datastream
¶
Add a datastream to the object.
| PARAMETER | DESCRIPTION |
|---|---|
dsdata
|
Datastream metadata to add.
TYPE:
|
replace
|
If True, replace existing datastream with the same dsid.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If datastream with the same dsid exists and replace is False. |
merge_datastream
¶
Merge the datastream metadata with another DSData object.
| PARAMETER | DESCRIPTION |
|---|---|
dsdata
|
Datastream metadata to merge.
TYPE:
|
get_datastreamdata
¶
Return a generator for all datastream metadata.
| RETURNS | DESCRIPTION |
|---|---|
None
|
Generator[DSData, None, None]: Generator of DSData objects. |
count_datastreams
¶
Return the number of datastreams.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of datastreams.
TYPE:
|
get_languages
¶
get_mainresource
¶
Return the main resource (datastream) of the object if set or None.
| RETURNS | DESCRIPTION |
|---|---|
DSData
|
The main resource datastream, or None if not set.
TYPE:
|
is_empty
¶
Return True if the object has no CSV metadata.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if object or datastream metadata is missing, False otherwise.
TYPE:
|
save
¶
Save the object metadata and datastreams to their respective CSV files.
| RAISES | DESCRIPTION |
|---|---|
FileExistsError
|
If CSV files already exist and ignore_existing_csv_files is False. |
clear
¶
Clear the object metadata and datastreams, and delete the CSV files.
Removes all metadata and deletes object.csv and datastreams.csv files if present.
validate
¶
Validate the object metadata and datastreams.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If metadata is missing or invalid. |
guess_mainresource
¶
Guess and set the main resource of the object based on the datastreams.
Heuristics
- If there is only one XML datastream besides DC.xml, use it as mainResource.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The guessed main resource ID, or empty string if not determined.
TYPE:
|