Skip to content

The objectdir module

This module provides some functions to deal with GAMS object directories

gamslib.objectdir

Module for object directory management and validation in GAMS library.

logger module-attribute

logger = logging.getLogger(__name__)

ObjectDirectoryValidationError

Bases: Exception

Exception raised when an object directory is invalid.

is_object_folder

is_object_folder(folder_path)

Check if the given folder is an object folder.

An object folder is defined as a folder that contains a DC.xml file.

PARAMETER DESCRIPTION
folder_path

Path to the folder to check.

TYPE: Path

RETURNS DESCRIPTION
bool

True if the folder is an object folder, False otherwise.

TYPE: bool

find_object_folders

find_object_folders(root_folder)

Find all object folders in the root folder or below.

PARAMETER DESCRIPTION
root_folder

Root directory to search for object folders.

TYPE: Path

YIELDS DESCRIPTION
Path

Path to each object folder containing a DC.xml file.

TYPE:: Path

Notes
  • Skips folders that do not contain a DC.xml file and logs a warning.

validate_directory_structure

validate_directory_structure(object_path)

Validate the structure of the object directory.

Structure is valid if it contains at least these files
  • DC.xml
  • object.csv
  • datastreams.csv
  • all files referenced in datastreams.csv
PARAMETER DESCRIPTION
object_path

Path to the object directory.

TYPE: Path

RAISES DESCRIPTION
ObjectDirectoryValidationError

If the directory structure is invalid.

validate_main_resource_id

validate_main_resource_id(object_dir)

Validate if the main resource file has the same ID as the object directory

Raise a ObjectDirectoryValidationError if the main resource is a TEI or LIDO file and the ID in this file does not have the same ID as the object directory.

In all other cases, this function does not raise an error.

PARAMETER DESCRIPTION
object_dir

Path to the object directory.

TYPE: Path

Raises: ObjectDirectoryValidationError: If the main resource file has the same ID as the object directory

validate_csv_files

validate_csv_files(object_path)

Validate the CSV files in the object directory.

PARAMETER DESCRIPTION
object_path

Path to the object directory.

TYPE: Path

RAISES DESCRIPTION
ObjectDirectoryValidationError

If any CSV file is invalid.

validate_dc_file

validate_dc_file(object_path)

Validate the DC.xml file in the object directory.

PARAMETER DESCRIPTION
object_path

Path to the object directory.

TYPE: Path

RAISES DESCRIPTION
ObjectDirectoryValidationError

If the DC.xml file is invalid.

validate_object_dir

validate_object_dir(object_path)

Check if everything needed is present in the object directory.

PARAMETER DESCRIPTION
object_path

Path to the object directory.

TYPE: Path

RAISES DESCRIPTION
ObjectDirectoryValidationError

If the directory or required files are missing, or if object.csv is invalid.