madbot_cli.status
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.
Attributes
| Name | Description |
|---|---|
COMMENT_WIDTH | The longest comment fields writes after a value; field tells the rest. |
LEVELS | The levels each choice of fields --level keeps. |
LEVEL_ORDER | The order of the fields of fields, by level. |
SAFE_KEY | A key of YAML that needs no quotes. |
YAML_WORDS | The words YAML reads as something else than a text. |
Functions
| Name | Description |
|---|---|
add_parts | Give each object field to fill its parts, read from the schema of the field. |
alias_of_object | Name a metadata object as by_alias designates it. |
browse_source | List what a source of the file holds at a path, with the external identifiers. |
cut_comment | Cut a comment too long for a line, saying where to read the rest. |
field_command | Give the command that tells all a field accepts. |
fields | List the metadata fields a repository asks for in a submission. |
has_problems | Tell whether a status shows a failure: a data not read, or a submission in error. |
merge_same_alias | Make one entry of the objects of a type that share an alias. |
metadata_fields | Gather the fields of the metadata objects of a submission, type by type. |
node_status | Tell where a node of the file stands, and the nodes under it. |
render_browse | Write what a source holds, with the external identifiers. |
render_fields | Write the metadata: part of a submission, to paste in the file and complete. |
render_node_status | Write the status of a node, then of the nodes under it, each one level further in. |
render_status | Write a status for a person to read. |
render_submission | Write the status of a submission for a person to read. |
source_status | Count the data of a source on a node by state. |
status | Tell where the deposit of a file stands in madbot. |
walk_status | List the status of each node of a status, at every depth. |
write_value | Write the value of a field, an object field without a value with its parts. |
yaml_key | Write a text as a key of YAML, quoted only when it needs to be. |
COMMENT_WIDTHattributemodule attribute#
COMMENT_WIDTH = 160The longest comment fields writes after a value; field tells the rest.
LEVELSattributemodule attribute#
LEVELS = {'mandatory': {'mandatory'}, 'recommended': {'mandatory', 'recommended'}}The levels each choice of fields --level keeps.
LEVEL_ORDERattributemodule attribute#
LEVEL_ORDER = {'mandatory': 0, 'recommended': 1, 'optional': 2}The order of the fields of fields, by level.
SAFE_KEYattributemodule attribute#
SAFE_KEY = re.compile('[A-Za-z][A-Za-z0-9_-]*')A key of YAML that needs no quotes.
YAML_WORDSattributemodule attribute#
YAML_WORDS = {'y', 'n', 'yes', 'no', 'on', 'off', 'true', 'false', 'null'}The words YAML reads as something else than a text.
add_partsfunction#
def add_parts(schemas: checks.Schemas, types: Mapping) -> NoneGive 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
| Name | Type | Description |
|---|---|---|
schemas | checks.Schemas | The schemas of the instance. |
types | mapping | The fields made by metadata_fields, completed in place. |
alias_of_objectfunction#
def alias_of_object(by_type: Mapping, metadata_object: Mapping) -> str | NoneName a metadata object as by_alias designates it.
Parameters
| Name | Type | Description |
|---|---|---|
by_type | mapping | The metadata of one type in the file. |
metadata_object | mapping | A metadata object of the submission. |
browse_sourcefunction#
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) -> dictList 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
| Name | Type | Default | Description |
|---|---|---|---|
client | Client | required | The client. |
manifest | Manifest | required | The deposit file. |
key | str | required | The key of the source in the file. |
path | list of str | required | The names of the containers to open, from the root. |
connect | bool | False | Create the connection when it does not exist yet, with the credentials of the file. Nothing else is written. |
search | str | 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 | None | The environment holding the credentials; os.environ by default. |
Returns
dictsource,path,created: whatconnectwrote, for a person, anditems: each object with itsname,external_id,typeandhas_children. Withsearch, alsosearch,count: the number of results in all, andmessage: why there is none, when the source says so.
Raises
MadbotError- When the source is not connected and
connectis false, or a name of the path is not found.
cut_commentfunction#
def cut_comment(text: str, more: str, width: int = COMMENT_WIDTH) -> strCut a comment too long for a line, saying where to read the rest.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | str | required | The comment. |
more | str | required | The command that tells the rest. |
width | int | COMMENT_WIDTH | The longest comment kept as is. |
Returns
str- The comment, or its beginning and the command.
field_commandfunction#
def field_command(field: Mapping) -> strGive the command that tells all a field accepts.
Parameters
| Name | Type | Description |
|---|---|---|
field | mapping | The field, with its slug and its source when known. |
Returns
str- Such as
madbot-cli field ena__sample__taxon --source ena.
fieldsfunction#
def fields(client: Client, manifest: Manifest, title: str, environ: Mapping[str, str] | None = None, level: str | None = None) -> dictList 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
| Name | Type | Default | Description |
|---|---|---|---|
client | Client | required | The client. |
manifest | Manifest | required | The deposit file. |
title | str | required | The title of the submission, in the file. |
environ | mapping | None | The environment holding the credentials; os.environ by default. |
level | str | 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 thevalueall its objects share, from the file or from madbot (None otherwise), and for an object field without a value itspartsand, when it has several forms, theformsit may take; andobjects: each object (label,alias) with its ownvaluesand its mandatory fields stillmissing.
Raises
MadbotError- When the file has no such submission, it is not prepared yet, or madbot cannot tell which submission it is.
has_problemsfunction#
def has_problems(result: Mapping) -> boolTell whether a status shows a failure: a data not read, or a submission in error.
Parameters
| Name | Type | Description |
|---|---|---|
result | mapping | A status made by status. |
Returns
bool- True when something failed.
merge_same_aliasfunction#
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
| Name | Type | Description |
|---|---|---|
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
countof objects it stands for and the slugs whose valuesdifferfrom one object to another (the first value is kept, and by_alias would give it to each); an object without an alias stays alone.
metadata_fieldsfunction#
def metadata_fields(wanted: Mapping, metadata_objects: list[dict], levels: set[str] | None = None) -> dictGather 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
| Name | Type | Default | Description |
|---|---|---|---|
wanted | mapping | required | The metadata of the submission in the file. |
metadata_objects | list of dict | required | The metadata objects of the submission, with their
summary_fields and metadata_items. |
levels | set of str | 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,
fieldsandobjects, asfieldsdescribes them. A field whose objects each hold a value of their own, and none the same, isper_object.
node_statusfunction#
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
Returns
tuple- The status of the node:
exists, itssources(counts of data by state and thefailedones with their error), thetasksstill running, its childnodes, those absent from the file (untracked), and itssubmissions(status,error_reason, thefailuremessage of its last task,errors,external_identifiers, datanot_in_deposit); and the data of its subtree.
render_browsefunction#
def render_browse(write: Any, result: Mapping) -> NoneWrite what a source holds, with the external identifiers.
Parameters
| Name | Type | Description |
|---|---|---|
write | callable | Writes a line. |
result | mapping | The listing made by browse_source. |
render_fieldsfunction#
def render_fields(write: Any, result: Mapping) -> NoneWrite the metadata: part of a submission, to paste in the file and complete.
Parameters
| Name | Type | Description |
|---|---|---|
write | callable | Writes a line. |
result | mapping | The fields made by fields. |
render_node_statusfunction#
def render_node_status(write: Any, node: Mapping, depth: int = 0) -> NoneWrite the status of a node, then of the nodes under it, each one level further in.
render_statusfunction#
def render_status(write: Any, result: Mapping) -> NoneWrite a status for a person to read.
Parameters
| Name | Type | Description |
|---|---|---|
write | callable | Writes a line. |
result | mapping | A status made by status. |
render_submissionfunction#
def render_submission(write: Any, submission: Mapping) -> NoneWrite the status of a submission for a person to read.
Parameters
| Name | Type | Description |
|---|---|---|
write | callable | Writes a line. |
submission | mapping | A submission of a status made by status. |
source_statusfunction#
def source_status(datalinks: list[dict], connection: Mapping) -> dictCount the data of a source on a node by state.
Parameters
| Name | Type | Description |
|---|---|---|
datalinks | list of dict | The datalinks of the node. |
connection | mapping | The plan of the connection of the source. |
Returns
dictconnected, the counts ofdataby state, and thefailedones with their error.
statusfunction#
def status(client: Client, manifest: Manifest, environ: Mapping[str, str] | None = None) -> dictTell where the deposit of a file stands in madbot.
Parameters
Returns
dictworkspace(None when it does not exist yet), thenodesat the top absent from the file (untracked), and for each node, asnode_statusgives it, its childnodes.
walk_statusfunction#
def walk_status(nodes: list[Mapping]) -> Iterator[Mapping]List the status of each node of a status, at every depth.
Parameters
| Name | Type | Description |
|---|---|---|
nodes | list of mapping | The status of the nodes at the top. |
Yields
mapping- The status of each node, before its children.
write_valuefunction#
def write_value(write: Any, indent: str, field: Mapping, value: Any, comment: str) -> NoneWrite the value of a field, an object field without a value with its parts.
yaml_keyfunction#
def yaml_key(text: str) -> strWrite a text as a key of YAML, quoted only when it needs to be.
Parameters
| Name | Type | Description |
|---|---|---|
text | str | The key. |
Returns
str- The key, as is or quoted.

