Zum Inhalt

undone_maker

undone_maker is a manually-invoked maintenance flow with two entirely different modes of operation, selected by whether the delete_issn_list parameter is empty:

  1. Bulk journal deletion: permanently removes one or more entire journal folders (every article, every module's output) from disk.
  2. Single-step rollback (the default): undoes the most recent module's run for every article under a set of journals, reverting each article to its state as of the module before that.

Both modes operate directly on folders under <data_root_not_backed_up>/<WDM_ROOT_FOLDER> and bypass the standard previous_module/temp-folder machinery entirely. This module reads and manipulates article folders directly with os.listdir/shutil/os.rename, not through utils.py's folder-lifecycle helpers.

Given the destructive nature of both modes, this should only be run deliberately by someone who understands exactly which ISSNs/articles they're targeting, not as a routine pipeline step, and not scheduled to run unattended.

The module contains one Python file:

  1. flow.py

flow.py

This file defines both the flow and all of its logic, using the Prefect library and prefect's get_run_logger (with log_prints=True). It uses the config file purely to resolve which ISSNs are associated with last_module, then works directly with raw folder listings from there.

undone_maker()

  • Required Parameters:

  • delete_issn_list (list): ISSNs whose entire journal folder should be permanently deleted. Default is [] — when empty, the rollback mode runs instead.

  • last_module (str): The name of the module whose run should be undone. Default is "dtd_scanner".
  • second_last_module (str): The name of the module that ran immediately before last_module. Default is "mdpi".
  • name_of_config_file (str): Name of the workflow config file, used only to resolve the ISSN list via get_module_context(..., last_module). Default is "config-test_crossrefcrawler.json".

  • Context for Use:

  • This function is the single entry point for both modes. It always starts by resolving issn_list from the config file (looking for journals whose modules list contains last_module), regardless of which mode ends up running.

### Mode 1 — Bulk journal deletion (delete_issn_list is non-empty)

This mode permanently deletes the entire local folder for each given ISSN via shutil.rmtree. This removes a journal's entire harvested dataset in one call.

There is no interactive confirmation: The only safeguard is a logged countdown — a sequence of logger.info/time.sleep calls counting down from 10, then two additional half/quarter-second-labeled steps, totaling roughly 17 seconds, before deletion begins. There's no prompt to type "yes" or otherwise confirm; the only way to stop it is to kill the running flow process before the countdown finishes.

### Mode 2 — Single-step rollback (delete_issn_list is empty, the default)

For each article under the resolved ISSNs, this mode attempts to undo last_module's run and revert the article to its state as of second_last_module:

  1. For any folder in the article directory whose name starts with last_module, a history.csv entry is written into it (Input: last_module, Outputs: [second_last_module]).
  2. If a stop-...-prefixed folder exists for the article, it is deleted outright, and the article is skipped (continue). No renaming happens in this case. This is actually the correct minimal action: if last_module's run ended in a stop folder, that means it never got far enough to touch second_last_module's content. Deleting the stop folder alone already restores the article to "only second_last_module completed" without needing to rename anything.
  3. Otherwise (no stop folder — meaning last_module completed normally), the article is reverted by relabeling: the now-empty second_last_module folder is deleted, and the last_module folder is renamed to take its place, matching the original date/time suffix. This makes last_module's entire output look like it was second_last_module's output, rather than truly restoring second_last_module's original pristine content. Any files last_module itself added remain in the folder, now mislabeled as having come from the earlier module. Rename failures are caught and logged as critical errors, and that article is skipped without stopping the run for the rest of the batch.

This rollback can only step back one module at a time (from last_module to second_last_module) and the two module names must be supplied correctly by the caller; there's no automatic detection of "what actually ran before what."

  • Example Usage:

  • ```python # Roll back dtd_scanner's most recent run, reverting to mdpi's output undone_maker(last_module="dtd_scanner", second_last_module="mdpi", name_of_config_file="config-test_crossrefcrawler.json")

    Permanently delete two entire journal folders — irreversible

    undone_maker(delete_issn_list=["1234-5678", "8765-4321"]) ```

  • Example Output (rollback mode):

  • INFO: Module name (->module_name): undone_maker. INFO: Number of journals: 1. INFO: ------------------- Iterate over journal 1422-0067 (1 of 1 - 100.0%) ------------------- DEBUG: [Article 'some-doi' from Journal '1422-0067'] mdpi folder exists. DEBUG: Deleted folder (->second_last_module_folder_path): '.../mdpi_2025-01-17'. DEBUG: Renamed folder '.../dtd_scanner_2025-01-17' to '.../mdpi_2025-01-17'.

  • Example Output (deletion mode):

  • WARNING: Danger! Directory destruct system is now activated. Cancel this run immediately if you don't want to lose data! INFO: Following journal directories in ... are doomed to death: ['1234-5678']. INFO: The option to override automatic deletion expires in t minus ten seconds. INFO: t - 10 s ... CRITICAL: The option to override detonation procedure has now expired. INFO: Blow up directory .../1234-5678. INFO: Successfully deleted 1234-5678.