create_bags
Overview
The create_bags module packages each processed article into a BagIt archive suitable for archival deposit. The bag contains all article files (metadata, XML, etc.) inherited from the previous module, plus a bag-info.txt file with Dublin Core metadata (title, authors, publisher, license, etc.) and BagIt manifest files. The finished bag is zipped and the unzipped folder is removed.
Module ordering: create_bags should run after check_license_information in the pipeline. It reads the normalized license link from the license.json file produced by that module and uses it to populate the dc.rights field of the bag. If check_license_information did not run first, license.json will be missing and dc.rights will be written as an empty string (with a warning logged).
The module contains two primary Python files:
flow.pytasks.py
flow.py
This file defines the main flow for bag creation. For each article, it fetches the journal's DDC classification (if not already cached), copies the previous module's contents into a temp directory, and delegates the actual bag creation to tasks.py.
create_bags()
-
Required Parameters:
-
name_of_config_file(str): Name of the configuration file. Default is"config-test_crossrefcrawler.json" -
test_copy(bool): Flag to indicate if it is a test run. Default isFalse -
Context for Use:
-
This function is the main entry point for the bag creation flow. It initializes the module-specific context, iterates over every article of every journal in the module context, and for each article calls
tasks.get_ddc,tasks.create_bag_zip, and finally writes a history.csv entry. Articles whose previous module has not been updated since the last run are skipped and counted separately. -
Example Usage:
-
python create_bags('config-test_crossrefcrawler.json', test_copy=False) -
Example Output:
-
INFO: Module name: create_bags INFO: Set base path to: /mnt/nas/wdm-test INFO: Module context: [{'ISSN': '2948-2143', 'position': 3, 'previous_module': 'check_license_information', ...}] INFO: Start bag creation for ISSN: 2948-2143. INFO: Journal path: /mnt/nas-tmp/wdm-test/Automatische_Prozessierung/2948-2143--2026-06-03-1780516203 INFO: Article: /mnt/nas-tmp/.../s42467-023-00015-y INFO: latest previous module: /mnt/nas-tmp/.../check_license_information_2025-01-17 INFO: Processed 3 out of 4 articles in journal: /mnt/nas-tmp/.../2948-2143--2026-06-03-1780516203 INFO: Skipped 1 articles in journal: /mnt/nas-tmp/.../2948-2143--2026-06-03-1780516203. These articles have not been updated by the previous module.
tasks.py
This file contains the task definitions used in the bag creation flow. It handles fetching Dewey Decimal Classification (DDC) subjects for the journal, reading the normalized license link from license.json, assembling the Dublin Core metadata dictionary, and producing the final zipped BagIt archive.
get_ddc()
-
Required Parameters:
-
journal_dir(pathlib.Path): Path to the journal directory -
issn(str): The journal's ISSN -
Context for Use:
-
This function fetches DDC (Dewey Decimal Classification) subjects for the journal if a DDC file does not already exist. It calls
ddc_utils.fetch_ddc(issn)to get the subjects from the external DDC service. If successful, subjects are written line-by-line to aDDC.txtfile inside the journal directory, and the ISSN is removed from the missing-DDC tracking file. If unsuccessful or no subjects are returned, the ISSN is added to the missing-DDC file for later manual review. -
Example Usage:
-
python get_ddc(journal_path, '2948-2143') -
Example Output:
-
A file at
<journal_dir>/DDC.txtcontaining subject codes, one per line. Log output:or (if not found):INFO: DDC information written successfully to DDC.txt fileINFO: DDC information not found for journal with ISSN: 2948-2143
create_bag_zip()
-
Required Parameters:
-
module_name(str): Name of the current module latest_previous_module(pathlib.Path): Path to the latest previous module directory-
journal_dir(pathlib.Path): Path to the journal directory -
Context for Use:
-
This is a thin orchestrator that calls
create_bagto produce the BagIt directory, thenzip_bagto compress it into a.ziparchive, thenremove_bagto delete the unzipped folder. Only the zipped archive remains after this function returns. -
Example Usage:
-
python create_bag_zip('create_bags', latest_previous_module, journal_path) -
Example Output:
-
A zipped bag at
<temp_current_module_dir>/<bag_name>.zip, with the unzipped folder deleted.
create_bag()
-
Required Parameters:
-
module_name(str): Name of the current module latest_previous_module(pathlib.Path): Path to the latest previous module directory-
journal_dir(pathlib.Path): Path to the journal directory -
Context for Use:
-
This is the core task of the module. It copies the temp module directory contents into a new bag directory, assembles the Dublin Core metadata dictionary (
dc.title,dc.creator,dc.rights, etc.), and callsbagit.make_bagto convert the folder into a BagIt archive with proper manifest and payload files. Thedc.rightsfield is populated from the normalizedlicense.jsonproduced by the upstreamcheck_license_informationmodule, not from the raw CrossRef metadata.Nonevalues in the metadata dict are converted to empty strings before being written tobag-info.txt. -
Example Usage:
-
python create_bag('create_bags', latest_previous_module, journal_path) -
Example Output:
-
A BagIt-format directory at
<temp_current_module_dir>/<bag_name>/containing:bagit.txt— BagIt version markerbag-info.txt— the Dublin Core metadatamanifest-sha256.txt— checksums of payload filestagmanifest-sha256.txt— checksums of tag filesdata/— the actual article files
get_documentation_data()
-
Required Parameters:
-
module_name(str): Name of the current module latest_previous_module(pathlib.Path): Path to the latest previous module directory-
current_datetime(dict): Dictionary containing the current date and timestamp -
Context for Use:
-
Builds the documentation data dictionary that will be written to
history.csvfor this article. TheInputfield lists every file name that ended up inside the bag'sdata/directory (except the documentation directory itself), joined by the standard delimiter. TheOutputsfield is the zipped bag file name. -
Example Usage:
-
python documentation_data = get_documentation_data('create_bags', latest_previous_module, current_datetime) -
Example Output:
-
python { 'Date': '2026-06-03', 'Input': 'metadata-article.json;license.json;s42467-023-00015-y.xml', 'Outputs': ['s42467-023-00015-y_bag.zip'] }
The lower-level helper functions in tasks.py are listed below.
get_normalized_license_link()
-
Required Parameters:
-
temp_current_module_dir(pathlib.Path): Path to the current temp module directory -
Context for Use:
-
Reads the normalized license link from
license.json(produced by the upstreamcheck_license_informationmodule) and returns the value of itslicenseLinkfield. If the file is missing or malformed, an empty string is returned and a warning is logged — this ensures that pipelines lackingcheck_license_informationstill complete, just with an emptydc.rightsfield and a visible warning.
get_bag_dir()
-
Required Parameters:
-
module_name(str): Name of the current module -
latest_previous_module(pathlib.Path): Path to the latest previous module directory -
Context for Use:
-
Returns the path where the unzipped BagIt directory will be created. The bag name is derived from
utils.get_bag_name.
read_ddc()
-
Required Parameters:
-
journal_dir(pathlib.Path): Path to the journal directory -
Context for Use:
-
Reads the first line of
DDC.txtif it exists in the journal directory and returns it as a string. Returns an empty list when the file is missing. Used bycreate_bagto populatedc.subject.
zip_bag()
-
Required Parameters:
-
bag_dir_path(pathlib.Path): Path to the unzipped BagIt directory -
Context for Use:
-
Uses
shutil.make_archiveto create a.ziparchive of the BagIt directory. If an archive with the same name already exists, it is replaced.
remove_bag()
-
Required Parameters:
-
bag_dir_path(pathlib.Path): Path to the unzipped BagIt directory -
Context for Use:
-
Removes the unzipped BagIt directory using
shutil.rmtree. Called afterzip_bagso that only the zipped archive remains.
get_file_names_in_archive()
-
Required Parameters:
-
zipped_bag_path(pathlib.Path): Path to the zipped bag archive -
Context for Use:
-
Introspects the contents of a zipped bag and returns the names of all files inside the
data/directory, excluding files indata/<DOCUMENTATION_DIR>. Used byget_documentation_datato build theInputfield of the history.csv entry.