# madbot_cli.plan

*module*

Compare a deposit file with what madbot holds, without writing anything.

`plan` reads madbot through the API, with lists rather than one request per
object, and returns for each object of the file what `apply` would do:
``create``, ``update`` or nothing (``unchanged``). It also reports what madbot
holds that the file does not mention, which `apply` leaves alone, and the
metadata a repository requires that the file does not give.

The functions that plan one kind of object are shared with
`madbot_cli.apply`, which runs them again after each step.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1-1)

## madbot_cli.plan.BY_ALIAS

*attribute* · *module attribute*

```python
BY_ALIAS = 'by_alias'
```

The key of a metadata type holding the values of single objects, by alias.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L53-53)

## madbot_cli.plan.CONNECT

*attribute* · *module attribute*

```python
CONNECT = 'connect'
```

The action on a connection that exists, for which the account has no working credentials yet.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L45-45)

## madbot_cli.plan.CREATE

*attribute* · *module attribute*

```python
CREATE = 'create'
```

The action on an object `apply` creates.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L39-39)

## madbot_cli.plan.DEPOSITED

*attribute* · *module attribute*

```python
DEPOSITED = 'deposited'
```

The state of a submission already sent to its repository: madbot cannot change it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L47-47)

## madbot_cli.plan.DEPOSITED_STATUSES

*attribute* · *module attribute*

```python
DEPOSITED_STATUSES = {'submission in progress', 'submitted', 'update available'}
```

States of a submission sent, or being sent, to its repository.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L50-50)

## madbot_cli.plan.LABEL_TEXT

*attribute* · *module attribute*

```python
LABEL_TEXT = 40
```

The longest text of a summary field kept in the name of a metadata object.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1231-1231)

## madbot_cli.plan.UNCHANGED

*attribute* · *module attribute*

```python
UNCHANGED = 'unchanged'
```

The action on an object madbot already holds as the file describes it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L43-43)

## madbot_cli.plan.UPDATE

*attribute* · *module attribute*

```python
UPDATE = 'update'
```

The action on an object `apply` changes.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L41-41)

## madbot_cli.plan.Linked

*class* · *dataclass*

```python
class Linked
```

The data of one node a submission chooses from.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L841-854)

### madbot_cli.plan.Linked.datalinks

*attribute* · *instance attribute*

```python
datalinks: list[dict]
```

The datalinks of the node.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L847-847)

### madbot_cli.plan.Linked.path

*attribute* · *class attribute* · *instance attribute*

```python
path: tuple[str, ...] = ()
```

The titles from the top of the workspace to the node.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L853-853)

### madbot_cli.plan.Linked.pending

*attribute* · *class attribute* · *instance attribute*

```python
pending: list[dict] = field(default_factory=list)
```

The data still to be linked to the node, from the plan of its data.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L849-849)

### madbot_cli.plan.Linked.title

*attribute* · *instance attribute*

```python
title: str
```

The path of the node, for a person.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L845-845)

### madbot_cli.plan.Linked.unresolved

*attribute* · *class attribute* · *instance attribute*

```python
unresolved: set[str] = field(default_factory=set)
```

The sources whose ``browse`` entries wait for the connection.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L851-851)

## madbot_cli.plan.State

*class* · *dataclass*

```python
class State
```

What madbot holds, read once for a plan.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L57-101)

### madbot_cli.plan.State.ambiguous

*attribute* · *class attribute* · *instance attribute*

```python
ambiguous: set[tuple[str, Any]] = field(default_factory=set)
```

What madbot gives to several objects, as ``(kind, key)``: ``node`` and
its path, or ``submission`` and its title. madbot does not keep titles
unique.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L69-69)

### madbot_cli.plan.State.children

*attribute* · *class attribute* · *instance attribute*

```python
children: dict[tuple[str, ...], list[dict]] = field(default_factory=dict)
```

The nodes madbot holds under each node of the file, by path; ``()`` for the top.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L65-65)

### madbot_cli.plan.State.connections

*attribute* · *class attribute* · *instance attribute*

```python
connections: list[dict] = field(default_factory=list)
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L67-67)

### madbot_cli.plan.State.nodes

*attribute* · *class attribute* · *instance attribute*

```python
nodes: dict[tuple[str, ...], dict] = field(default_factory=dict)
```

The nodes of the file madbot holds, by path of titles.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L63-63)

### madbot_cli.plan.State.plugins

*attribute* · *instance attribute*

```python
plugins: list[dict]
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L61-61)

### madbot_cli.plan.State.submissions

*attribute* · *class attribute* · *instance attribute*

```python
submissions: dict[str, dict] = field(default_factory=dict)
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L68-68)

### madbot_cli.plan.State.workspace

*attribute* · *class attribute* · *instance attribute*

```python
workspace: dict | None = None
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L62-62)

### madbot_cli.plan.State.read_children

*method*

```python
def read_children(client: Client, nodes: Iterable[Node], parent: tuple[str, ...] = ()) -> None
```

Read the nodes of the file madbot holds, level by level.

Only the nodes of the file are opened: the children of a node absent
from the file are not read.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `nodes` (`iterable of Node`) — The nodes of the file under `parent`.
- `parent` (`tuple of str`) (default: `()`) — The path of their parent, whose children are already read.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L74-101)

## madbot_cli.plan.actions

*function*

```python
def actions(result: Mapping) -> Iterable[str]
```

List the action of every object of a plan.

**Parameters**

- `result` (`mapping`) — A plan.

**Yields**

- (`str`) — The action of each object, a metadata value counting as one.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1866-1894)

## madbot_cli.plan.association_candidates

*function*

```python
def association_candidates(datalinks: Iterable[Mapping], sources: Mapping[str, Mapping], connections: Mapping[str, Mapping], keys: Iterable[str]) -> list[dict]
```

List the data of a node an association can take, linked or about to be.

**Parameters**

- `datalinks` (`iterable of mapping`) — The datalinks of the node.
- `sources` (`mapping`) — The plan of the data of each source of the node, by key; empty once the data are linked.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `keys` (`iterable of str`) — The sources of the node.

**Returns**

- (`list of dict`) — Each data as ``{name, data, connection}``; ``data`` is None for a data still to link, which also gives the key of its ``source`` (its connection may not exist yet). The data madbot failed to read are left out.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L675-725)

## madbot_cli.plan.association_fields

*function*

```python
def association_fields(client: Client, rules: Iterable[Mapping], cache: dict | None) -> dict[str, dict]
```

Read the madbot fields the associations of some rules have, once per run.

**Parameters**

- `client` (`Client`) — The client.
- `rules` (`iterable of mapping`) — The ``associations`` of a node.
- `cache` (`dict`) — The fields already read, under ``association_fields``.

**Returns**

- (`dict`) — The fields, by slug.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L728-755)

## madbot_cli.plan.browse_folder

*function*

```python
def browse_folder(client: Client, connection_id: str, path: list[str], cache: dict | None = None) -> list[dict]
```

List the data of a folder of a source, once per plan.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `path` (`list of str`) — The names of the containers to open, from the root.
- `cache` (`dict`) (default: `None`) — The folders already listed, kept between calls.

**Returns**

- (`list of dict`) — ``external_id`` and ``name`` of each object of the folder, sorted by name.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L358-384)

## madbot_cli.plan.by_title

*function*

```python
def by_title(objects: Iterable[Mapping], kind: str, ambiguous: set, under: tuple[str, ...] | None = None) -> dict[str, dict]
```

Index objects of madbot by their title, noting the titles given twice.

**Parameters**

- `objects` (`iterable of mapping`) — The nodes or the submissions.
- `kind` (`str`) — ``node`` or ``submission``.
- `ambiguous` (`set`) — Receives ``(kind, title)`` for each title given to several objects, ``(kind, path)`` for nodes.
- `under` (`tuple of str`) (default: `None`) — The path of the parent of nodes.

**Returns**

- (`dict`) — Each object by its title.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L104-137)

## madbot_cli.plan.entry_label

*function*

```python
def entry_label(entry: Mapping) -> str
```

Describe a data entry of the file for a person.

**Parameters**

- `entry` (`mapping`) — A data entry: ``external_id``, ``browse``, ``match`` or ``names``.

**Returns**

- (`str`) — Such as ``campaign/raw/*.tif``, ``campaign/raw/{a.tif, b.tif}`` or ``match *.tif``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L330-355)

## madbot_cli.plan.existing_node

*function*

```python
def existing_node(state: State, path: tuple[str, ...]) -> dict | None
```

Find the node madbot holds for a node of the file.

**Parameters**

- `state` (`State`) — What madbot holds.
- `path` (`tuple of str`) — The path of titles of the node.

**Returns**

- (`dict or None`) — The node, None when madbot has none there.

**Raises**

- `MadbotError` — When madbot has several nodes of that title at that place: the file
cannot say which.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L140-169)

## madbot_cli.plan.existing_submission

*function*

```python
def existing_submission(state: State, submission: Submission, repository_id: str | None) -> dict | None
```

Find the submission madbot holds for a submission of the file.

A submission is found by its title, and must go to the repository the
file names: one of the same title to another repository is another
submission, made in the web application.

**Parameters**

- `state` (`State`) — What madbot holds.
- `submission` (`Submission`) — The submission, from the file.
- `repository_id` (`str or None`) — The connection to its repository, None when it is to be created.

**Returns**

- (`dict or None`) — The submission, None when madbot has none of that title.

**Raises**

- `MadbotError` — When madbot has several submissions of that title, or one to another
repository.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L172-220)

## madbot_cli.plan.identity

*function*

```python
def identity(item: Mapping) -> tuple
```

Tell which data a datalink or a data still to link stands for.

**Parameters**

- `item` (`mapping`) — A datalink, or a data still to link from the plan of a node.

**Returns**

- (`tuple`) — Its connection and its external identifier.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L857-874)

## madbot_cli.plan.label_of

*function*

```python
def label_of(metadata_object: Mapping) -> str
```

Name a metadata object for a person.

**Parameters**

- `metadata_object` (`mapping`) — A metadata object of a submission.

**Returns**

- (`str`) — Its type and the values of its summary fields, such as ``sample plate3``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1208-1228)

## madbot_cli.plan.missing_names

*function*

```python
def missing_names(missing: list[str], found: list[Mapping]) -> str
```

Name the names a folder does not hold, each with the names close to it.

**Parameters**

- `missing` (`list of str`) — The names not found.
- `found` (`list of mapping`) — What the folder holds.

**Returns**

- (`str`) — Such as ``readme.md (close to it: README.md)``; when no name is close to any, what the folder holds, in a few names, such as ``notes.txt (found: a.csv, b.csv)``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L461-490)

## madbot_cli.plan.moved_data

*function*

```python
def moved_data(in_submission: Iterable[Mapping], selected: Iterable[Mapping]) -> list[dict]
```

Find the data a submission holds through another node than the one the file chooses.

apply never moves them: it would take the data out of the submission
first, and apply never deletes. A data held without a datalink is left
out: it goes through no node to compare.

**Parameters**

- `in_submission` (`iterable of mapping`) — The data of the submission, as the API returns them.
- `selected` (`iterable of mapping`) — The datalinks the file selects, each with the path of its node in ``through``.

**Returns**

- (`list of dict`) — For each, its ``name``, the title of the node it goes through in madbot (``current``) and the path of the one of the file (``through``).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1359-1399)

## madbot_cli.plan.moved_warning

*function*

```python
def moved_warning(label: str, moved: Mapping) -> str
```

Say that a data goes through another node than the one the file chooses.

**Parameters**

- `label` (`str`) — The submission, in the message.
- `moved` (`mapping`) — A data found by `moved_data`.

**Returns**

- (`str`) — The warning.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1402-1423)

## madbot_cli.plan.name_of

*function*

```python
def name_of(item: Mapping) -> str
```

Name a datalink or a data still to link for a person.

**Parameters**

- `item` (`mapping`) — A datalink, or a data still to link.

**Returns**

- (`str`) — Its name, else its external identifier.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L877-893)

## madbot_cli.plan.node_action

*function*

```python
def node_action(existing: Mapping | None) -> str
```

Tell what apply does to a node of the file.

**Parameters**

- `existing` (`mapping or None`) — The node madbot holds, None when it has none.

**Returns**

- (`str`) — `CREATE` without a node; `UPDATE` for a node madbot holds as a draft (`madbot_cli.operations.NODE_PENDING`), which apply makes a node in use; `UNCHANGED` otherwise.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1557-1575)

## madbot_cli.plan.plan

*function*

```python
def plan(client: Client, manifest: Manifest, environ: Mapping[str, str] | None = None) -> dict
```

Compare a deposit file with madbot, without writing anything.

**Parameters**

- `client` (`Client`) — The client.
- `manifest` (`Manifest`) — The deposit file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials; `os.environ` by default.

**Returns**

- (`dict`) — The ``workspace``, the plan of the connection of each source in ``sources``, and the plan of each node in ``nodes``; what the workspace holds that the file does not mention in ``untracked``; ``errors`` and ``warnings``; and the counts of ``summary``.

**Raises**

- `madbot_cli.checks.CheckError` — When the file gives values madbot would refuse, once madbot is read
and before anything is planned.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1762-1863)

## madbot_cli.plan.plan_connection

*function*

```python
def plan_connection(state: State, spec: Mapping[str, Any], environ: Mapping[str, str] | None = None, *, source: bool = False) -> dict
```

Plan the connection to a source or a repository.

**Parameters**

- `state` (`State`) — What madbot holds.
- `spec` (`mapping`) — ``plugin``, ``shared_params`` and ``credentials_env`` from the file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials; `os.environ` by default.
- `source` (`bool`) (default: `False`) — True for a source of data: its public data may be read without credentials when its plugin allows it. A repository always needs them to submit.

**Returns**

- (`dict`) — ``plugin`` (its identifier), ``shared_params``, ``action`` (``create``, ``connect`` or ``unchanged``), ``id`` and ``name`` of an existing connection, ``credentials`` (``given``, ``missing``, ``not needed`` or ``public``: a source read without credentials, its public data only).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L260-327)

## madbot_cli.plan.plan_data

*function*

```python
def plan_data(items: Iterable[Mapping], connection_id: str | None, datalinks: Iterable[Mapping]) -> list[dict]
```

Plan the data of a source on a node.

**Parameters**

- `items` (`iterable of mapping`) — The data of the source, from `resolve_data`.
- `connection_id` (`str or None`) — The connection to the source, None when it is to be created.
- `datalinks` (`iterable of mapping`) — The datalinks of the node.

**Returns**

- (`list of dict`) — Each data with its ``action``, and for a linked one its ``datalink``, ``data``, ``status`` and ``error``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L536-583)

## madbot_cli.plan.plan_metadata

*function*

```python
def plan_metadata(wanted: Mapping[str, Mapping], metadata_objects: Iterable[Mapping]) -> dict
```

Compare the metadata a file gives with those of a submission.

**Parameters**

- `wanted` (`mapping`) — The ``metadata`` of the submission in the file.
- `metadata_objects` (`iterable of mapping`) — The metadata objects of the submission, with their ``metadata_items``.

**Returns**

- (`dict`) — ``writes``: ``{object, label, field, current, value, action}`` for each value to set (``create``) or to replace (``update``); ``unchanged``: the count of values already right; ``missing``: ``{object, label, field, name}`` for each mandatory field without a value; ``errors``: values for a field of the repository that this object does not have, such as a field of a sample given under the study, left unwritten; ``warnings``: values the file gives for no object.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1257-1356)

## madbot_cli.plan.plan_node

*function*

```python
def plan_node(client: Client, state: State, node: Node, connections: Mapping[str, Mapping], environ: Mapping[str, str] | None = None, cache: dict | None = None) -> tuple[dict, list[Linked]]
```

Plan a node of the file, what it holds, and the nodes under it.

The submissions of a node are planned once the nodes under it are, as
they take their data in the whole subtree.

**Parameters**

- `client` (`Client`) — The client, with the workspace set when it exists.
- `state` (`State`) — What madbot holds.
- `node` (`Node`) — The node, from the file.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.
- `cache` (`dict`) (default: `None`) — The folders of the sources already listed.

**Returns**

- (`tuple`) — The plan of the node, with its ``action``, the plan of the data of each source it names in ``sources``, its ``samples``, ``associations``, ``submissions`` and child ``nodes``, and what madbot holds on the node that the file does not mention (``untracked``); and the data of the node and of each node under it, for the submissions above.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1578-1698)

## madbot_cli.plan.plan_node_associations

*function*

```python
def plan_node_associations(client: Client, node: Node, node_id: str | None, datalinks: list[dict], sources: Mapping[str, Mapping], connections: Mapping[str, Mapping], cache: dict | None = None, complete: bool = True) -> dict | None
```

Plan the associations of a node from the rules of the file.

**Parameters**

- `client` (`Client`) — The client, with the workspace set when it exists.
- `node` (`Node`) — The node, from the file.
- `node_id` (`str or None`) — The node in madbot; None before it is created.
- `datalinks` (`list of dict`) — The datalinks of the node.
- `sources` (`mapping`) — The plan of the data of each source of the node, by key.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `cache` (`dict`) (default: `None`) — What the run already read.
- `complete` (`bool`) (default: `True`) — Whether every data of the node is known: False while a source waits for its connection.

**Returns**

- (`dict or None`) — The plan of `associations.plan_associations`, its ``later`` also true when the suggestions of madbot wait for data still to link; None when the file gives no rule.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L758-835)

## madbot_cli.plan.plan_node_samples

*function*

```python
def plan_node_samples(node: Node, datalinks: list[dict], samples: list[dict], bound: Mapping[str, set[str]], sources: Mapping[str, Mapping], connections: Mapping[str, Mapping]) -> dict | None
```

Plan the samples of a node from the rule of the file.

Data still to be linked are counted when their name is known.

**Parameters**

- `node` (`Node`) — The node, from the file.
- `datalinks` (`list of dict`) — The datalinks of the node.
- `samples` (`list of dict`) — The samples of the node.
- `bound` (`mapping`) — The datalinks bound to each sample, by sample identifier.
- `sources` (`mapping`) — The plan of the data of each source of the node, by key.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.

**Returns**

- (`dict or None`) — The plan of `operations.plan_samples`, each sample with its ``action``; None when the file gives no rule.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L615-672)

## madbot_cli.plan.plan_sources

*function*

```python
def plan_sources(state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> tuple[dict[str, dict], list[str]]
```

Plan the connection of each source of the file, once for the whole file.

**Parameters**

- `state` (`State`) — What madbot holds.
- `manifest` (`Manifest`) — The deposit file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.

**Returns**

- (`tuple`) — The plan of each connection by key, and the errors: two keys that stand for the same connection once their plugins are known.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1720-1759)

## madbot_cli.plan.plan_submission

*function*

```python
def plan_submission(client: Client, state: State, submission: Submission, subtree: list[Linked], connections: Mapping[str, Mapping], environ: Mapping[str, str] | None = None, cache: dict | None = None) -> dict
```

Plan a submission of the file.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `state` (`State`) — What madbot holds.
- `submission` (`Submission`) — The submission, from the file.
- `subtree` (`list of Linked`) — The data of its node, first, then of each node under it.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.
- `cache` (`dict`) (default: `None`) — The folders of the sources already listed.

**Returns**

- (`dict`) — ``title``, ``action``, ``id``, ``status``, the ``repository`` connection, the ``data`` to ``add`` or ``present``, those ``waiting`` to be read, the entries ``unresolved`` until their source is connected, those ``outside`` the subtree, the node each data to ``add`` or ``waiting`` goes ``through`` (in the same order, None when the subtree has one node), the data ``moved`` (held through another node than the one chosen), ``not_in_deposit`` and ``not_selected``, the ``metadata`` plan, and ``errors`` and ``warnings`` of its entries.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1426-1551)

## madbot_cli.plan.read_state

*function*

```python
def read_state(client: Client, manifest: Manifest) -> State
```

Read the workspace of a deposit file and what it holds.

The client is set to the workspace when it exists.

**Parameters**

- `client` (`Client`) — The client.
- `manifest` (`Manifest`) — The deposit file.

**Returns**

- (`State`) — The plugins of the instance, and the workspace with the nodes of the file and their children, the connections and the submissions, when it exists.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L223-254)

## madbot_cli.plan.resolve_data

*function*

```python
def resolve_data(client: Client, entries: Iterable[Mapping], connections: Mapping[str, Mapping], cache: dict | None = None) -> dict
```

Turn the data entries of a node into external identifiers, by source.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `entries` (`iterable of mapping`) — The data entries of the node.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `cache` (`dict`) (default: `None`) — The folders already listed.

**Returns**

- (`dict`) — By source key: ``items`` (each data found, once), ``unresolved`` (the ``browse`` entries left for after the connection) and ``errors``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L493-533)

## madbot_cli.plan.resolve_entry

*function*

```python
def resolve_entry(client: Client, entry: Mapping, connection: Mapping, cache: dict | None = None) -> dict
```

Turn a data entry of the file into the external identifiers it designates in its source.

A ``browse`` entry is looked for in the source, through the API; it can
only be when the account is connected to the source. A name of
``names`` the folder does not hold is an error, and the entry then
designates nothing: naming a file says it must exist.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `entry` (`mapping`) — An ``external_id`` or ``browse`` entry.
- `connection` (`mapping`) — The connection of its source, from `plan_connection`.
- `cache` (`dict`) (default: `None`) — The folders already listed.

**Returns**

- (`dict`) — ``items``: ``{source, external_id, name, browse}`` for each data; ``unresolved``: the label of the entry when it waits for the connection, else None; ``error``: what could not be found, else None.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L387-458)

## madbot_cli.plan.select

*function*

```python
def select(client: Client, submission: Submission, subtree: list[Linked], connections: Mapping[str, Mapping], cache: dict | None = None) -> dict
```

Pick the data a submission takes in its node and the nodes under it, entry by entry.

Each entry is resolved like one of a node, then only the data linked to
the node of the submission or to a node under it are kept; ``match``
and ``names`` alone filter those data by their name in madbot. A data
enters once, through one node: the only one it is linked to, or the one
``via`` names when it is linked to several. A data an entry designates
that no node of the subtree holds is reported, never added.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission` (`Submission`) — The submission, from the file.
- `subtree` (`list of Linked`) — The data of its node, first, then of each node under it.
- `connections` (`mapping`) — The plan of the connection of each source of the file, by key.
- `cache` (`dict`) (default: `None`) — The folders already listed.

**Returns**

- (`dict`) — ``datalinks``: those taken, each with the path of its node in ``through``; ``pending``: the data taken once linked; ``unresolved``: the entries found once their source is connected, each as ``{source, entry}``; ``outside``: the names of data no node of the subtree holds; ``errors`` and ``warnings``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1131-1175)

## madbot_cli.plan.short_text

*function*

```python
def short_text(text: str, width: int = LABEL_TEXT) -> str
```

Cut a text to a width, on a word when it can.

**Parameters**

- `text` (`str`) — The text.
- `width` (`int`) (default: `LABEL_TEXT`) — The longest text kept.

**Returns**

- (`str`) — The text, or its beginning followed by ``…``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1235-1254)

## madbot_cli.plan.source_datalinks

*function*

```python
def source_datalinks(datalinks: Iterable[Mapping], connection_ids: Iterable[str | None]) -> list[dict]
```

Keep the datalinks whose data come from some connections.

**Parameters**

- `datalinks` (`iterable of mapping`) — The datalinks of a node.
- `connection_ids` (`iterable of str`) — The connections.

**Returns**

- (`list of dict`) — The datalinks of those connections.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L589-612)

## madbot_cli.plan.submission_actions

*function*

```python
def submission_actions(submission: Mapping) -> Iterable[str]
```

List the actions of a submission as apply counts its changes.

An existing submission is updated only through the data it receives and
the metadata values written: those are counted, one each, not the
submission on top of them.

**Parameters**

- `submission` (`mapping`) — The plan of a submission.

**Yields**

- (`str`) — Its own action when it is created, deposited or left as is; then a creation per data added, and the action of each metadata value.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1897-1923)

## madbot_cli.plan.summarize

*function*

```python
def summarize(result: Mapping) -> dict
```

Count what a plan would do.

**Parameters**

- `result` (`mapping`) — A plan.

**Returns**

- (`dict`) — ``create``, ``update``, ``unchanged`` and ``deposited`` counts, ``to_submit`` (submissions not sent yet), ``missing_metadata``, ``missing_association_values`` (associations whose fields are not all valid), and ``changes``: whether `apply` would write anything.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1926-1962)

## madbot_cli.plan.values_for

*function*

```python
def values_for(wanted: Mapping[str, Mapping], metadata_object: Mapping) -> dict
```

Return the values a file gives for one metadata object.

**Parameters**

- `wanted` (`mapping`) — The ``metadata`` of the submission in the file.
- `metadata_object` (`mapping`) — A metadata object of the submission, with its ``type`` and ``summary_fields``.

**Returns**

- (`dict`) — Each value by field slug: those of the type, then those of the object found by its alias. An empty value is no value: apply never clears one, a skeleton of `madbot-cli fields` pasted as it is writes nothing, and a value left empty under ``by_alias`` leaves the value of the type in place.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1178-1205)

## madbot_cli.plan.walk_plans

*function*

```python
def walk_plans(nodes: Iterable[Mapping]) -> Iterator[Mapping]
```

List the plans of the nodes of a plan, at every depth, each before its children.

**Parameters**

- `nodes` (`iterable of mapping`) — The plans of the nodes at the top.

**Yields**

- (`mapping`) — The plan of each node.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/plan.py#L1701-1717)
