Skip to content

gamspreprocessor.gams3

This module exports digital objects from a GAMS3 instance to object dirs. The most important function is export_objects(), a generator function which yields Gams3Object objects containing data about the export status.

gamspreprocessor.gams3

This module provides the main API forexporting GAMS 3 objects.

Gams3Object

Gams3Object(pid, base_url)

A Fedora 3 object.

Initialize the object with its PID and base URL.

NAMESPACES class-attribute

NAMESPACES = {'fedora': 'http://www.fedora.info/definitions/1/0/access/'}

pid instance-attribute

pid = pid

base_url instance-attribute

base_url = base_url

object_url instance-attribute

object_url = f'{self.base_url}/objects/{requests.utils.quote(self.pid)}'

object_properties instance-attribute

object_properties = None

audit_trail instance-attribute

audit_trail = None

status instance-attribute

status = ExportStatus.PENDING

exported_files instance-attribute

exported_files = []

warnings instance-attribute

warnings = []

errors instance-attribute

errors = []

get_datastreams

get_datastreams()

Yield all datastreams of the object as DataStream objects.

export

export(output_root, overwrite=False, strip_prefix=False, colon_replacement='%3A')

Export this object and its datastreams into an object-specific directory.

This method raises an Export Error if an error occurs during export. The object is aware of its status which can be checked after export: the status attribute has the following possible values implement as ExportStatus Enum:

  • ExportStatus.PENDING (initial state),
  • ExportStatus.EXPORTED (export successful),
  • ExportStatus.REPLACED (existing export was replaced),
  • ExportStatus.IGNORED (export skipped due to existing export and overwrite=False),
  • ExportStatus.ERROR (an error occurred during export).

You might also want to check the warnings and errors attributes of the object after export, which contain any warnings or errors that occurred during export.

PARAMETER DESCRIPTION
output_root

Root directory where the object directory will be created.

TYPE: Path

overwrite

Whether to overwrite an existing object directory. If an object directory already exists at the target location and overwrite is True, it will be deleted and re-exported. If overwrite is False, the existing directory is skipped.

TYPE: bool DEFAULT: False

strip_prefix

Whether to strip the "o:" prefix from the PID when naming the subdirectories.

TYPE: bool DEFAULT: False

colon_replacement

String to replace ":" in PIDs when naming subdirectories.

TYPE: str DEFAULT: '%3A'

Returns: None

RAISES DESCRIPTION
ExportError

If an error occurs during export of the object or any of its datastream

ExportError

Bases: Exception

Custom exception for errors during export of a GAMS 3 object.

export_objects

export_objects(pid_pattern, output_dir, overwrite=False, base_url='https://gams.uni-graz.at/archive', strip_prefix=False, colon_replacement='%3A')

Export all objects matching the given PID pattern from a GAMS 3 repository.

Yield each exported Gams3Object. Export exceptions are converted to warnings, so you want to check the status attribute of each object. All warnings and errors are also collected in the warnings and errors attributes of each object, respectively.

PARAMETER DESCRIPTION
pid_pattern

A pattern to match PIDs, e.g. "o:foo*"

TYPE: str

output_dir

Path to the directory to save the exported objects to.

TYPE: Path

overwrite

Whether to overwrite existing object directories and files. If set to False, objects which already exist in the output directory are skipped.

TYPE: bool DEFAULT: False

base_url

Base URL of the GAMS 3 repository, default is "https://gams.uni-graz.at/archive"

TYPE: str DEFAULT: 'https://gams.uni-graz.at/archive'

strip_prefix

Whether to strip the type prefix (e.g. o:) from the PID when naming the subdirectories.

TYPE: bool DEFAULT: False

colon_replacement

String to replace ":" in PIDs when naming subdirectories, default is "%3A". Ignored if strip_prefix is True.

TYPE: str DEFAULT: '%3A'

Yields: Each exported Gams3Object.