|
| 1 | +from typing import List |
| 2 | +from ._utils import dump_request |
| 3 | + |
| 4 | + |
| 5 | +def reroute_links(to_delete: List, staging: str, url: str, dry_run: bool = False) -> List: |
| 6 | + """Reroute symbolic links to files in directories that are to be deleted, e.g., by :py:func:`~pygobbler.remove_project.remove_project`. |
| 7 | + This preserves the validity of links within the Gobbler registry. |
| 8 | +
|
| 9 | + Note that rerouting does not actually delete the directories specified in ``to_delete``. |
| 10 | + Deletion requires separate invocations of :py:func:`~pygobbler.remove_project.remove_project` and friends - preferably after the user has verified that rerouting was successful! |
| 11 | +
|
| 12 | + Rerouting is not necessary if ``to_delete`` consists only of probational versions, or projects/assets containing only probational versions. |
| 13 | + The Gobbler should never create links to files in probational version directories. |
| 14 | +
|
| 15 | + Args: |
| 16 | + to_delete: |
| 17 | + List of projects, assets or versions to be deleted. |
| 18 | + Each entry should be a dicionary containing at least the ``project`` name. |
| 19 | + When deleting an asset, the inner list should contain an additional ``asset`` name. |
| 20 | + When deleting a version, the inner list should contain additional ``asset`` and ``version`` names. |
| 21 | + Different inner lists may specify different projects, assets or versions. |
| 22 | +
|
| 23 | + staging: |
| 24 | + Path to the staging directory. |
| 25 | +
|
| 26 | + url: |
| 27 | + URL for the Gobbler REST API. |
| 28 | +
|
| 29 | + dry_run: |
| 30 | + Whether to perform a dry run of the rerouting. |
| 31 | +
|
| 32 | + Returns: |
| 33 | + List of dictionaries. |
| 34 | + Each dictionary represents a rerouting action and contains the following fields. |
| 35 | +
|
| 36 | + - ``path``, string containing the path to a symbolic link in the registry that was changed by rerouting. |
| 37 | + - ``copy``, boolean indicating whether the link at ``path`` was replaced by a copy of its target file. |
| 38 | + If ``False``, the link was merely updated to refer to a new target file. |
| 39 | + - ``source``, the path to the target file that caused rerouting of ``path``. |
| 40 | + Specifically, this is a file in one of the to-be-deleted directories specified in ``to_delete``. |
| 41 | + If ``copy = TRUE``, this is the original linked-to file that was copied to ``path``. |
| 42 | +
|
| 43 | + If ``dry_run = False``, the registry is modified as described by the rerouting actions. |
| 44 | + Otherwise, no modifications are performed to the registry. |
| 45 | + """ |
| 46 | + out = dump_request(staging, url, "reroute_links", { "to_delete": to_delete, "dry_run": dry_run }) |
| 47 | + return out["changes"] |
0 commit comments