Skip to content

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

NameDescription
COMMENT_WIDTHThe longest comment fields writes after a value; field tells the rest.
LEVELSThe levels each choice of fields --level keeps.
LEVEL_ORDERThe order of the fields of fields, by level.
SAFE_KEYA key of YAML that needs no quotes.
YAML_WORDSThe words YAML reads as something else than a text.

Functions

NameDescription
add_partsGive each object field to fill its parts, read from the schema of the field.
alias_of_objectName a metadata object as by_alias designates it.
browse_sourceList what a source of the file holds at a path, with the external identifiers.
cut_commentCut a comment too long for a line, saying where to read the rest.
field_commandGive the command that tells all a field accepts.
fieldsList the metadata fields a repository asks for in a submission.
has_problemsTell whether a status shows a failure: a data not read, or a submission in error.
merge_same_aliasMake one entry of the objects of a type that share an alias.
metadata_fieldsGather the fields of the metadata objects of a submission, type by type.
node_statusTell where a node of the file stands, and the nodes under it.
render_browseWrite what a source holds, with the external identifiers.
render_fieldsWrite the metadata: part of a submission, to paste in the file and complete.
render_node_statusWrite the status of a node, then of the nodes under it, each one level further in.
render_statusWrite a status for a person to read.
render_submissionWrite the status of a submission for a person to read.
source_statusCount the data of a source on a node by state.
statusTell where the deposit of a file stands in madbot.
walk_statusList the status of each node of a status, at every depth.
write_valueWrite the value of a field, an object field without a value with its parts.
yaml_keyWrite a text as a key of YAML, quoted only when it needs to be.

COMMENT_WIDTHattributemodule attribute#

COMMENT_WIDTH = 160

The 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) -> 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

NameTypeDescription
schemaschecks.SchemasThe schemas of the instance.
typesmappingThe fields made by metadata_fields, completed in place.

alias_of_objectfunction#

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

Name a metadata object as by_alias designates it.

Parameters

NameTypeDescription
by_typemappingThe metadata of one type in the file.
metadata_objectmappingA 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.

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) -> 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

NameTypeDefaultDescription
clientClientrequiredThe client.
manifestManifestrequiredThe deposit file.
keystrrequiredThe key of the source in the file.
pathlist of strrequiredThe names of the containers to open, from the root.
connectboolFalseCreate the connection when it does not exist yet, with the credentials of the file. Nothing else is written.
searchstrNoneThe 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.
environmappingNoneThe 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.

cut_commentfunction#

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

NameTypeDefaultDescription
textstrrequiredThe comment.
morestrrequiredThe command that tells the rest.
widthintCOMMENT_WIDTHThe longest comment kept as is.

Returns

str
The comment, or its beginning and the command.

field_commandfunction#

def field_command(field: Mapping) -> str

Give the command that tells all a field accepts.

Parameters

NameTypeDescription
fieldmappingThe 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) -> 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

NameTypeDefaultDescription
clientClientrequiredThe client.
manifestManifestrequiredThe deposit file.
titlestrrequiredThe title of the submission, in the file.
environmappingNoneThe environment holding the credentials; os.environ by default.
levelstrNonemandatory 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.

has_problemsfunction#

def has_problems(result: Mapping) -> bool

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

Parameters

NameTypeDescription
resultmappingA 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

NameTypeDescription
objectslist of dictThe 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.

metadata_fieldsfunction#

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

NameTypeDefaultDescription
wantedmappingrequiredThe metadata of the submission in the file.
metadata_objectslist of dictrequiredThe metadata objects of the submission, with their summary_fields and metadata_items.
levelsset of strNoneThe 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.

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

NameTypeDescription
clientClientThe client, with its workspace set.
stateStateWhat madbot holds.
nodeNodeThe node, from the file.
connectionsmappingThe plan of the connection of each source of the file, by key.
environmappingThe 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.

render_browsefunction#

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

Write what a source holds, with the external identifiers.

Parameters

NameTypeDescription
writecallableWrites a line.
resultmappingThe listing made by browse_source.

render_fieldsfunction#

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

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

Parameters

NameTypeDescription
writecallableWrites a line.
resultmappingThe fields made by fields.

render_node_statusfunction#

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

NameTypeDefaultDescription
writecallablerequiredWrites a line.
nodemappingrequiredThe status of the node.
depthint0How deep the node is, 0 at the top of the workspace.

render_statusfunction#

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

Write a status for a person to read.

Parameters

NameTypeDescription
writecallableWrites a line.
resultmappingA status made by status.

render_submissionfunction#

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

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

Parameters

NameTypeDescription
writecallableWrites a line.
submissionmappingA submission of a status made by status.

source_statusfunction#

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

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

Parameters

NameTypeDescription
datalinkslist of dictThe datalinks of the node.
connectionmappingThe plan of the connection of the source.

Returns

dict
connected, the counts of data by state, and the failed ones with their error.

statusfunction#

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

Tell where the deposit of a file stands in madbot.

Parameters

NameTypeDefaultDescription
clientClientrequiredThe client.
manifestManifestrequiredThe deposit file.
environmappingNoneThe 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.

walk_statusfunction#

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

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

Parameters

NameTypeDescription
nodeslist of mappingThe 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) -> None

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

Parameters

NameTypeDescription
writecallableWrites a line.
indentstrThe indentation of the key.
fieldmappingThe field, with its slug and, as add_parts gives them, its parts and forms.
valueAnyIts value, None to write it empty.
commentstrWhat to say of it.

yaml_keyfunction#

def yaml_key(text: str) -> str

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

Parameters

NameTypeDescription
textstrThe key.

Returns

str
The key, as is or quoted.