Skip to content

The managecsv modul

gamslib.objectcsv.manage_csv

Functions to collect and update object and datastream CSV files for GAMS projects.

Provides utilities to aggregate metadata from all object folders into central CSV/XLSX files, and to distribute updated metadata back to individual object folders.

logger module-attribute

logger = logging.getLogger()

collect_csv_data

collect_csv_data(object_root_dir, object_csv_path=None, datastream_csv_path=None)

Collect metadata from all object folders below object_root_dir and save to combined CSV files.

PARAMETER DESCRIPTION
object_root_dir

Root directory containing all object folders.

TYPE: Path

object_csv_path

Path to save combined object metadata CSV. Defaults to 'object.csv' in CWD.

TYPE: Path | None DEFAULT: None

datastream_csv_path

Path to save combined datastream metadata CSV. Defaults to 'datastreams.csv' in CWD.

TYPE: Path | None DEFAULT: None

RETURNS DESCRIPTION
ObjectCollection

Collection containing all object and datastream metadata.

TYPE: ObjectCollection

Notes
  • Reads all object.csv and datastreams.csv files below object_root_dir.
  • Saves aggregated metadata to the specified CSV files.

split_from_xlsx

split_from_xlsx(object_root_dir, xlsx_file=None)

Update object folder CSV metadata from a combined XLSX file.

PARAMETER DESCRIPTION
object_root_dir

Root directory containing all object folders.

TYPE: Path

xlsx_file

Path to the XLSX file. Defaults to 'all_objects.xlsx' in CWD.

TYPE: Path | None DEFAULT: None

RETURNS DESCRIPTION
tuple[int, int]

tuple[int, int]: Number of updated objects and number of updated datastreams.

RAISES DESCRIPTION
UserWarning

If an object directory does not exist.

Notes
  • Reads the XLSX file created by collect_csv_data().
  • Updates object.csv and datastreams.csv files in all object folders below object_root_dir.

split_from_csv

split_from_csv(object_root_dir, object_csv_path=None, ds_csv_path=None)

Update object folder CSV metadata from combined CSV files.

PARAMETER DESCRIPTION
object_root_dir

Root directory containing all object folders.

TYPE: Path

object_csv_path

Path to combined object metadata CSV. Defaults to 'object.csv' in CWD.

TYPE: Path | None DEFAULT: None

ds_csv_path

Path to combined datastream metadata CSV. Defaults to 'datastreams.csv' in CWD.

TYPE: Path | None DEFAULT: None

RETURNS DESCRIPTION
tuple[int, int]

tuple[int, int]: Number of updated objects and number of updated datastreams.

RAISES DESCRIPTION
UserWarning

If an object directory does not exist.

Notes
  • Reads the CSV files created by collect_csv_data().
  • Updates object.csv and datastreams.csv files in all object folders below object_root_dir.