Skip to content

The ObjectCSVManager class

gamslib.objectcsv.objectcsvmanager.ObjectCSVManager

ObjectCSVManager(obj_dir, ignore_existing_csv_files=False)

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: Path

ignore_existing_csv_files

If True, ignore existing CSV files when writing.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
FileNotFoundError

If the object directory does not exist.

InvalidCSVFileError

If the CSV files are malformed.

obj_dir instance-attribute

obj_dir = obj_dir

object_id instance-attribute

object_id = self.obj_dir.name

set_object

set_object(object_data, replace=False)

Set the object metadata.

PARAMETER DESCRIPTION
object_data

Object metadata to set.

TYPE: ObjectData

replace

If True, replace existing object data.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
ValueError

If object data is already set and replace is False.

merge_object

merge_object(object_data)

Merge the object metadata with another ObjectData object.

PARAMETER DESCRIPTION
object_data

Object metadata to merge.

TYPE: ObjectData

get_object

get_object()

Return the object metadata.

RETURNS DESCRIPTION
ObjectData

The object metadata, or None if not set.

TYPE: ObjectData

add_datastream

add_datastream(dsdata, replace=False)

Add a datastream to the object.

PARAMETER DESCRIPTION
dsdata

Datastream metadata to add.

TYPE: DSData

replace

If True, replace existing datastream with the same dsid.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
ValueError

If datastream with the same dsid exists and replace is False.

merge_datastream

merge_datastream(dsdata)

Merge the datastream metadata with another DSData object.

PARAMETER DESCRIPTION
dsdata

Datastream metadata to merge.

TYPE: DSData

get_datastreamdata

get_datastreamdata()

Return a generator for all datastream metadata.

RETURNS DESCRIPTION
None

Generator[DSData, None, None]: Generator of DSData objects.

count_datastreams

count_datastreams()

Return the number of datastreams.

RETURNS DESCRIPTION
int

Number of datastreams.

TYPE: int

get_languages

get_languages()

Return the languages of the datastreams ordered by frequency.

RETURNS DESCRIPTION
list[str]

list[str]: List of language codes ordered by frequency.

get_mainresource

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: DSData | None

is_empty

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: bool

save

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()

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()

Validate the object metadata and datastreams.

RAISES DESCRIPTION
ValueError

If metadata is missing or invalid.

guess_mainresource

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: None