Skip to content

gamspreprocessor.projectsplitter

Splits up a directory structure typically used for GAMS 3 ingest into object directories expected by the SIP packager of GAMS 5.

If an object already exists in a GAMS3 repository, using the gamspreprocessor.gams3 exporter might be easier to use.

The important functions API wise are:

gamspreprocessor.projectsplitter

Split project files into objects directories.

This package contains modules for splitting up project folders into object directories.

BookKeeper

BookKeeper(storage_path)

A class to keep track of files that have been processed.

As the project dir also contains referenced data streams (images, etc.), we need to keep track of which files have been processed and which have not. It important for the incremental processing of the project that the user can find out which files have not been processed yet.

Initialize the BookKeeper object.

'data_path' is the path to the file where the bookkeeping data is stored.

If you plan to run the splitter multiple times for a single project, make sure that the 'data_path' is the same for all runs.

FILENAME class-attribute instance-attribute

FILENAME = '.bookkeeping.json'

storage_path instance-attribute

storage_path = storage_path

save

save()

Write data to disk.

add_pid

add_pid(filepath, pid)

Mark a file as used for an object with ID pid.

As a file can be used by more than one object, we keep the objects it is referenced in as list of object pids.

remove_pid

remove_pid(pid)

Remove object ID pid from all entries.

The is useful if an existing object is replaced by a new one.

get_unhandled

get_unhandled()

Return a list of paths for all files that have not been consumed yet.

reset

reset()

Reset the bookkeeper.

get_pids_for_file

get_pids_for_file(filepath)

Return a list of object pids for a file.

update

update(project_path)

Merge already registered files with newly collected files.

Also remove files which have been deleted since last run. 'project_path' is the root directory of the project files.

ProjectSplitter

ProjectSplitter(output_dir, project_dir, replace_existing_object_dirs=False)

Class to split a project into single objects.

Provides as split method to create a object folder for the file given as argument.

Initialize the ProjectSplitter.

Arguments: output_dir: The directory where the object directories will be created. project_dir: The directory containing the original data. replace_existing_object_dirs: If True, existing object directories will be replaced. Default is False.

output_dir instance-attribute

output_dir = output_dir

project_dir instance-attribute

project_dir = project_dir

replace_existing_object_dirs instance-attribute

replace_existing_object_dirs = replace_existing_object_dirs

make_object_source

make_object_source(source_file, use_format='auto', strip_prefix=True, strip_extension=False)

ObjectSource factory.

Return an ObjectSource or a subclass of ObjectSource representing the source file. The type of the returned class depends on mimetype and objecttype.

Raises a FileExistsError if the directory already exists (ie. the object has already been split).

split

split(sourcefile, objecttype='auto', strip_prefix=True, strip_extension=False)

Convert sourcefile into an object directory.

Arguments: sourcefile: Path to the source file to be processed. objecttype: The format to use for the source file. Can be 'auto', 'tei' or 'lido'. strip_prefix: If True, the prefix of the pid ('o:') will be removed.

Return a list files (Path objects) which have been copied to the object directory.

update_bookkeeper

update_bookkeeper()

Update the bookkeeper with all files in the project directory.

reset

reset()

Reset the bookkeeper.

list_unhandled_files

list_unhandled_files(output_dir)

Return files that are still unhandled in the given object directory tree.

split_project_files

split_project_files(output_dir, sourcefiles, object_format='auto', reset=False, replace=False, strip_prefix=False)

Split one or more source files into object directories.

Returns a tuple with the number of object directories created and the number of files copied into those directories.