The createcsv modul¶
gamslib.objectcsv.create_csv
¶
Create object.csv and datastreams.csv files for GAMS objects.
This module generates object.csv and datastreams.csv files for one or more object folders.
It uses data from the DC.xml file and the project configuration to populate metadata fields.
If information is missing, fields are left blank or filled with default values.
is_datastream_file
¶
Determine if a file should be treated as a datastream file.
Excludes files named 'object.csv' or 'datastreams.csv', and files matching ignore patterns specified in the configuration.
| PARAMETER | DESCRIPTION |
|---|---|
ds_file
|
Path to the candidate datastream file.
TYPE:
|
configuration
|
Project configuration containing ignore patterns.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the file should be used as a datastream, False otherwise.
TYPE:
|
get_rights
¶
Retrieve the rights information for an object or datastream.
Lookup order:
- Value from Dublin Core metadata (DC.xml).
- Value from project configuration.
- Default value if none found.
Args:
- config (Configuration): Project configuration.
- dc (DublinCore): Dublin Core metadata object.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Rights value.
TYPE:
|
extract_dsid
¶
Extract and validate the datastream ID from a file path.
If keep_extension is False, attempts to remove the file extension from the ID. Validates the resulting ID format.
| PARAMETER | DESCRIPTION |
|---|---|
datastream
|
Path or filename of the datastream. |
keep_extension
|
Whether to keep the file extension in the ID.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The extracted datastream ID.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the resulting ID is invalid. |
detect_languages
¶
Detect the language(s) of a file.
Returns detected language(s) as a string separated by the given delimiter. (Currently returns an empty string; language detection is not implemented.)
| PARAMETER | DESCRIPTION |
|---|---|
ds_file
|
Path to the file.
TYPE:
|
delimiter
|
Delimiter for joining detected languages.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Detected languages, or empty string if none.
TYPE:
|
collect_object_data
¶
Collect metadata for an object to populate object.csv.
Resolves values from Dublin Core metadata and project configuration.
| PARAMETER | DESCRIPTION |
|---|---|
pid
|
Object identifier.
TYPE:
|
config
|
Project configuration.
TYPE:
|
dc
|
Dublin Core metadata object.
TYPE:
|
use_subjects_as_tags
|
Whether to use dc:subjects as tags. (Default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObjectData
|
Populated object metadata.
TYPE:
|
make_ds_title
¶
Generate a title for a datastream based on its ID and format.
| PARAMETER | DESCRIPTION |
|---|---|
dsid
|
Datastream ID.
TYPE:
|
format_info
|
Format information for the datastream.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Generated datastream title.
TYPE:
|
make_ds_description
¶
Generate a description for a datastream based on its ID and format.
Uses the format subtype as the description if available.
| PARAMETER | DESCRIPTION |
|---|---|
dsid
|
Datastream ID.
TYPE:
|
format_info
|
Format information for the datastream.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Datastream description, or empty string if not available.
TYPE:
|
collect_datastream_data
¶
Collect metadata for a single datastream to populate datastreams.csv.
Uses file information, format detection, and configuration values.
| PARAMETER | DESCRIPTION |
|---|---|
ds_file
|
Path to the datastream file.
TYPE:
|
config
|
Project configuration.
TYPE:
|
dc
|
Dublin Core metadata object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DSData
|
Populated datastream metadata.
TYPE:
|
create_csv
¶
Generate object.csv and datastreams.csv for a single object directory.
Existing CSV files are not overwritten unless 'force_overwrite' is True. Metadata is collected from DC.xml and configuration.
| PARAMETER | DESCRIPTION |
|---|---|
object_directory
|
Path to the object directory.
TYPE:
|
configuration
|
Project configuration.
TYPE:
|
force_overwrite
|
Whether to overwrite existing CSV files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObjectCSVManager | None
|
ObjectCSVManager | None: Manager for the created CSV files, or None if not created. |
update_csv
¶
Update existing CSV files for an object directory with new metadata.
Adds new datastreams and updates metadata if configuration or DC.xml has changed. Existing CSV files are updated, not overwritten.
| PARAMETER | DESCRIPTION |
|---|---|
object_directory
|
Path to the object directory.
TYPE:
|
configuration
|
Project configuration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObjectCSVManager | None
|
ObjectCSVManager | None: Manager for the updated CSV files, or None if not updated. |
create_csv_files
¶
create_csv_files(root_folder, config, force_overwrite=False, update=False, use_subjects_as_tags=False)
Create or update CSV files for all objects under the given root folder.
Iterates through all object directories found below root_folder and creates or updates their object.csv and datastreams.csv files.
| PARAMETER | DESCRIPTION |
|---|---|
root_folder
|
Root directory containing object folders.
TYPE:
|
config
|
Project configuration.
TYPE:
|
force_overwrite
|
If True, overwrite existing CSV files.
TYPE:
|
update
|
If True, update existing CSV files instead of creating new ones.
TYPE:
|
use_subjects_as_tags
|
If True, insert all dc:subject entries as tags in object.csv
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ObjectCSVManager]
|
list[ObjectCSVManager]: List of managers for the processed object directories. |