# madbot_cli.status

*module*

Read what madbot holds for a deposit file: the state, the fields to fill, a source.

`status` tells where a deposit stands: the data madbot read or failed to
read, the tasks still running, and each submission with the identifiers its
repository gave. `fields` writes the ``metadata:`` part a repository asks
for, ready to complete. `browse` lists what a source holds, with the external
identifiers the file can name. None of them writes, except `browse` when
asked to connect a source.

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

## madbot_cli.status.COMMENT_WIDTH

*attribute* · *module attribute*

```python
COMMENT_WIDTH = 160
```

The longest comment `fields` writes after a value; `field` tells the rest.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L784-784)

## madbot_cli.status.LEVELS

*attribute* · *module attribute*

```python
LEVELS = {'mandatory': {'mandatory'}, 'recommended': {'mandatory', 'recommended'}}
```

The levels each choice of ``fields --level`` keeps.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L446-449)

## madbot_cli.status.LEVEL_ORDER

*attribute* · *module attribute*

```python
LEVEL_ORDER = {'mandatory': 0, 'recommended': 1, 'optional': 2}
```

The order of the fields of `fields`, by level.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L660-660)

## madbot_cli.status.SAFE_KEY

*attribute* · *module attribute*

```python
SAFE_KEY = re.compile('[A-Za-z][A-Za-z0-9_-]*')
```

A key of YAML that needs no quotes.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L663-663)

## madbot_cli.status.YAML_WORDS

*attribute* · *module attribute*

```python
YAML_WORDS = {'y', 'n', 'yes', 'no', 'on', 'off', 'true', 'false', 'null'}
```

The words YAML reads as something else than a text.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L665-665)

## madbot_cli.status.add_parts

*function*

```python
def add_parts(schemas: checks.Schemas, types: Mapping) -> None
```

Give each object field to fill its parts, read from the schema of the field.

Only the fields written empty somewhere are read: those without a value
all their objects share.

**Parameters**

- `schemas` (`checks.Schemas`) — The schemas of the instance.
- `types` (`mapping`) — The fields made by `metadata_fields`, completed in place.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L453-478)

## madbot_cli.status.alias_of_object

*function*

```python
def alias_of_object(by_type: Mapping, metadata_object: Mapping) -> str | None
```

Name a metadata object as ``by_alias`` designates it.

**Parameters**

- `by_type` (`mapping`) — The metadata of one type in the file.
- `metadata_object` (`mapping`) — A metadata object of the submission.

**Returns**

- (`str or None`) — The alias the file gives it; or else the value of its summary field named an alias, or the first of its summary values (a repository may give a description or a taxon among them); None when it has none.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L629-657)

## madbot_cli.status.browse_source

*function*

```python
def browse_source(client: Client, manifest: Manifest, key: str, path: list[str], *, connect: bool = False, search: str | None = None, environ: Mapping[str, str] | None = None) -> dict
```

List what a source of the file holds at a path, with the external identifiers.

With `search`, the objects of the source that match a text instead, in
the folder of the path or the whole source: a source of public data,
such as Zenodo, lists nothing at its root, and its records are found by
identifier, DOI or title.

**Parameters**

- `client` (`Client`) — The client.
- `manifest` (`Manifest`) — The deposit file.
- `key` (`str`) — The key of the source in the file.
- `path` (`list of str`) — The names of the containers to open, from the root.
- `connect` (`bool`) (default: `False`) — Create the connection when it does not exist yet, with the credentials of the file. Nothing else is written.
- `search` (`str`) (default: `None`) — The text to search in the folder of the path, or the whole source when the path is empty; the first page of results is given.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials; `os.environ` by default.

**Returns**

- (`dict`) — ``source``, ``path``, ``created``: what `connect` wrote, for a person, and ``items``: each object with its ``name``, ``external_id``, ``type`` and ``has_children``. With `search`, also ``search``, ``count``: the number of results in all, and ``message``: why there is none, when the source says so.

**Raises**

- `MadbotError` — When the source is not connected and `connect` is false, or a name
of the path is not found.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L854-962)

## madbot_cli.status.cut_comment

*function*

```python
def cut_comment(text: str, more: str, width: int = COMMENT_WIDTH) -> str
```

Cut a comment too long for a line, saying where to read the rest.

**Parameters**

- `text` (`str`) — The comment.
- `more` (`str`) — The command that tells the rest.
- `width` (`int`) (default: `COMMENT_WIDTH`) — The longest comment kept as is.

**Returns**

- (`str`) — The comment, or its beginning and the command.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L808-829)

## madbot_cli.status.field_command

*function*

```python
def field_command(field: Mapping) -> str
```

Give the command that tells all a field accepts.

**Parameters**

- `field` (`mapping`) — The field, with its ``slug`` and its ``source`` when known.

**Returns**

- (`str`) — Such as ``madbot-cli field ena__sample__taxon --source ena``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L788-805)

## madbot_cli.status.fields

*function*

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

List the metadata fields a repository asks for in a submission.

madbot makes the metadata objects of a submission once its data are in
it: the submission must have been prepared by `apply` first. A value
goes at the level of the type when every object has it, and under
``by_alias`` otherwise, so that the part written, pasted in the file,
gives each object the value it has.

**Parameters**

- `client` (`Client`) — The client.
- `manifest` (`Manifest`) — The deposit file.
- `title` (`str`) — The title of the submission, in the file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials; `os.environ` by default.
- `level` (`str`) (default: `None`) — ``mandatory`` or ``recommended``: only the fields of this level, the recommended ones with the mandatory ones. Every field by default.

**Returns**

- (`dict`) — For each type of metadata object, ``fields``: each field (``slug``, ``name``, ``level``, ``description``) with the ``value`` all its objects share, from the file or from madbot (None otherwise), and for an object field without a value its ``parts`` and, when it has several forms, the ``forms`` it may take; and ``objects``: each object (``label``, ``alias``) with its own ``values`` and its mandatory fields still ``missing``.

**Raises**

- `MadbotError` — When the file has no such submission, it is not prepared yet, or
madbot cannot tell which submission it is.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L374-443)

## madbot_cli.status.has_problems

*function*

```python
def has_problems(result: Mapping) -> bool
```

Tell whether a status shows a failure: a data not read, or a submission in error.

**Parameters**

- `result` (`mapping`) — A status made by `status`.

**Returns**

- (`bool`) — True when something failed.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L244-261)

## madbot_cli.status.merge_same_alias

*function*

```python
def merge_same_alias(objects: list[dict]) -> list[dict]
```

Make one entry of the objects of a type that share an alias.

``by_alias`` gives its values to every object the alias names: two
objects of one alias, such as the samples ENA makes for each file of a
pair not grouped in an association, are written once, as YAML holds a
key once.

**Parameters**

- `objects` (`list of dict`) — The objects of one type, as `metadata_fields` makes them.

**Returns**

- (`list of dict`) — One entry per alias, in the order of the objects, with the ``count`` of objects it stands for and the slugs whose values ``differ`` from one object to another (the first value is kept, and by_alias would give it to each); an object without an alias stays alone.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L587-626)

## madbot_cli.status.metadata_fields

*function*

```python
def metadata_fields(wanted: Mapping, metadata_objects: list[dict], levels: set[str] | None = None) -> dict
```

Gather the fields of the metadata objects of a submission, type by type.

Every field is listed, those that name an object (its summary fields,
such as its title or alias) too: a repository may ask for them, as ENA
does for the description of a study and the taxon of a sample. The value
of a summary field madbot holds is not repeated under ``by_alias``, where
the alias already names the object: madbot keeps it.

**Parameters**

- `wanted` (`mapping`) — The ``metadata`` of the submission in the file.
- `metadata_objects` (`list of dict`) — The metadata objects of the submission, with their ``summary_fields`` and ``metadata_items``.
- `levels` (`set of str`) (default: `None`) — The levels of the fields to keep, with any field the file gives a value; every field by default.

**Returns**

- (`dict`) — For each type, ``fields`` and ``objects``, as `fields` describes them. A field whose objects each hold a value of their own, and none the same, is ``per_object``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L481-584)

## madbot_cli.status.node_status

*function*

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

Tell where a node of the file stands, and the nodes under it.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `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`) — The environment holding the credentials.

**Returns**

- (`tuple`) — The status of the node: ``exists``, its ``sources`` (counts of data by state and the ``failed`` ones with their error), the ``tasks`` still running, its child ``nodes``, those absent from the file (``untracked``), and its ``submissions`` (``status``, ``error_reason``, the ``failure`` message of its last task, ``errors``, ``external_identifiers``, data ``not_in_deposit``); and the data of its subtree.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L123-222)

## madbot_cli.status.render_browse

*function*

```python
def render_browse(write: Any, result: Mapping) -> None
```

Write what a source holds, with the external identifiers.

**Parameters**

- `write` (`callable`) — Writes a line.
- `result` (`mapping`) — The listing made by `browse_source`.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L965-1007)

## madbot_cli.status.render_fields

*function*

```python
def render_fields(write: Any, result: Mapping) -> None
```

Write the ``metadata:`` part of a submission, to paste in the file and complete.

**Parameters**

- `write` (`callable`) — Writes a line.
- `result` (`mapping`) — The fields made by `fields`.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L669-745)

## madbot_cli.status.render_node_status

*function*

```python
def render_node_status(write: Any, node: Mapping, depth: int = 0) -> None
```

Write the status of a node, then of the nodes under it, each one level further in.

**Parameters**

- `write` (`callable`) — Writes a line.
- `node` (`mapping`) — The status of the node.
- `depth` (`int`) (default: `0`) — How deep the node is, 0 at the top of the workspace.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L286-325)

## madbot_cli.status.render_status

*function*

```python
def render_status(write: Any, result: Mapping) -> None
```

Write a status for a person to read.

**Parameters**

- `write` (`callable`) — Writes a line.
- `result` (`mapping`) — A status made by `status`.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L264-283)

## madbot_cli.status.render_submission

*function*

```python
def render_submission(write: Any, submission: Mapping) -> None
```

Write the status of a submission for a person to read.

**Parameters**

- `write` (`callable`) — Writes a line.
- `submission` (`mapping`) — A submission of a status made by `status`.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L328-368)

## madbot_cli.status.source_status

*function*

```python
def source_status(datalinks: list[dict], connection: Mapping) -> dict
```

Count the data of a source on a node by state.

**Parameters**

- `datalinks` (`list of dict`) — The datalinks of the node.
- `connection` (`mapping`) — The plan of the connection of the source.

**Returns**

- (`dict`) — ``connected``, the counts of ``data`` by state, and the ``failed`` ones with their error.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L82-120)

## madbot_cli.status.status

*function*

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

Tell where the deposit of a file stands in madbot.

**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`) — ``workspace`` (None when it does not exist yet), the ``nodes`` at the top absent from the file (``untracked``), and for each node, as `node_status` gives it, its child ``nodes``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L44-79)

## madbot_cli.status.walk_status

*function*

```python
def walk_status(nodes: list[Mapping]) -> Iterator[Mapping]
```

List the status of each node of a status, at every depth.

**Parameters**

- `nodes` (`list of mapping`) — The status of the nodes at the top.

**Yields**

- (`mapping`) — The status of each node, before its children.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L225-241)

## madbot_cli.status.write_value

*function*

```python
def write_value(write: Any, indent: str, field: Mapping, value: Any, comment: str) -> None
```

Write the value of a field, an object field without a value with its parts.

**Parameters**

- `write` (`callable`) — Writes a line.
- `indent` (`str`) — The indentation of the key.
- `field` (`mapping`) — The field, with its ``slug`` and, as `add_parts` gives them, its ``parts`` and ``forms``.
- `value` (`Any`) — Its value, None to write it empty.
- `comment` (`str`) — What to say of it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L748-781)

## madbot_cli.status.yaml_key

*function*

```python
def yaml_key(text: str) -> str
```

Write a text as a key of YAML, quoted only when it needs to be.

**Parameters**

- `text` (`str`) — The key.

**Returns**

- (`str`) — The key, as is or quoted.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/status.py#L832-848)
