weaver.cli

Module Contents

weaver.cli.ProcessSchemaType[source]
weaver.cli.LOGGER[source]
weaver.cli.OPERATION_ARGS_TITLE = Operation Arguments[source]
weaver.cli.OPTIONAL_ARGS_TITLE = Optional Arguments[source]
weaver.cli.REQUIRED_ARGS_TITLE = Required Arguments[source]
weaver.cli._json2text(data: Any)str[source]
class weaver.cli.OperationResult(success: Optional[bool] = None, message: Optional[str] = None, body: Optional[Union[str, weaver.typedefs.JSON]] = None, headers: Optional[weaver.typedefs.HeadersType] = None, text: Optional[str] = None, code: Optional[int] = None, **kwargs)[source]

Data container for any WeaverClient operation results.

Parameters
  • success – Success status of the operation.

  • message – Detail extracted from response content if available.

  • headers – Headers returned by the response for reference.

  • body – Content of JSON response or fallback in plain text.

  • text – Pre-formatted text representation of body.

Initialize self. See help(type(self)) for accurate signature.

success :Optional[bool] = False[source]
message :Optional[str] =[source]
headers :Optional[weaver.typedefs.HeadersType][source]
body :Optional[Union[weaver.typedefs.JSON, str]][source]
code :Optional[int][source]
property text(self)str[source]
class weaver.cli.WeaverClient(url=None)[source]

Client that handles common HTTP requests with a Weaver or similar OGC API - Processes instance.

monitor_timeout = 60[source]
monitor_interval = 5[source]
processes[source]

Alias of capabilities() for Process listing.

_get_url(self: Optional[str], url)str[source]
static _parse_url(url)[source]
static _parse_result(response: requests.Response, message: Optional[str] = None)OperationResult[source]
static _parse_deploy_body(body: Optional[Union[weaver.typedefs.JSON, str]], process_id: Optional[str])OperationResult[source]
static _parse_deploy_package(body: weaver.typedefs.JSON, cwl: Optional[weaver.typedefs.CWL], wps: Optional[str], process_id: Optional[str], headers: weaver.typedefs.HeadersType)OperationResult[source]
_parse_job_ref(self: str, job_reference: Optional[str], url=None)Tuple[Optional[str], Optional[str]][source]
static _parse_auth_token(token: Optional[str], username: Optional[str], password: Optional[str])weaver.typedefs.HeadersType[source]
deploy(self: Ellipsis, process_id: Optional[str] = None, body: Optional[Union[weaver.typedefs.JSON, str]] = None, cwl: Optional[Union[weaver.typedefs.CWL, str]] = None, wps: Optional[str] = None, token: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, undeploy: bool = False, url: Optional[str] = None)OperationResult[source]

Deploy a new Process with specified metadata and reference to an Application Package.

The referenced Application Package must be one of: - CWL body, local file or URL in JSON or YAML format - WPS process URL with XML response - WPS-REST process URL with JSON response - OGC API - Processes process URL with JSON response

If the reference is resolved to be a Workflow, all its underlying Process steps must be available under the same URL that this client was initialized with.

Parameters
  • process_id – Desired process identifier. Can be omitted if already provided in body contents or file.

  • body – Literal JSON contents, either using string representation of actual Python objects forming the request body, or file path/URL to YAML or JSON contents of the request body. Other parameters (process_id, cwl) can override corresponding fields within the provided body.

  • cwl – Literal JSON or YAML contents, either using string representation of actual Python objects, or file path/URL with contents of the CWL definition of the Application package to be inserted into the body.

  • wps – URL to an existing WPS process (WPS-1/2 or WPS-REST/OGC-API).

  • token – Authentication token for accessing private Docker registry if CWL refers to such image.

  • username – Username to form the authentication token to a private Docker registry.

  • password – Password to form the authentication token to a private Docker registry.

  • undeploy – Perform undeploy step as applicable prior to deployment to avoid conflict with exiting Process.

  • url – Instance URL if not already provided during client creation.

Returns

Results of the operation.

undeploy(self: str, process_id: Optional[str], url=None)OperationResult[source]

Undeploy an existing Process.

Parameters
  • process_id – Identifier of the process to undeploy.

  • url – Instance URL if not already provided during client creation.

capabilities(self: Optional[str], url=None)OperationResult[source]

List all available Process on the instance.

Parameters

url – Instance URL if not already provided during client creation.

describe(self: str, process_id: Optional[str], url: Optional[weaver.processes.constants.ProcessSchemaType] = None, schema=PROCESS_SCHEMA_OGC)OperationResult[source]

Describe the specified Process.

Parameters
  • process_id – Identifier of the process to describe.

  • url – Instance URL if not already provided during client creation.

  • schema – Representation schema of the returned process description.

static _parse_inputs(inputs: Optional[Union[str, weaver.typedefs.JSON]])Union[OperationResult, weaver.typedefs.ExecutionInputsMap][source]

Parse multiple different representation formats and input sources into standard OGC inputs.

Schema OGC is selected to increase compatibility coverage with potential non-Weaver servers only conforming to standard OGC API - Processes.

Inputs can be represented as CLI option string arguments, file path to load contents from, or directly supported list or mapping of execution inputs definitions.

_update_files(self: weaver.typedefs.ExecutionInputsMap, inputs: Optional[str], url=None)Tuple[weaver.typedefs.ExecutionInputsMap, weaver.typedefs.HeadersType][source]

Replaces local file paths by references uploaded to the Vault.

See also

Parameters

inputs – Input values for submission of Process execution.

Returns

Updated inputs.

execute(self: str, process_id: Optional[Union[str, weaver.typedefs.JSON]], inputs: bool = None, monitor: Optional[int] = False, timeout: Optional[int] = None, interval: Optional[str] = None, url=None)OperationResult[source]

Execute a Job for the specified Process with provided inputs.

When submitting inputs with OGC API - Processes schema, top-level inputs key is expected. Under it, either the mapping (key-value) or listing (id,value) representation are accepted. If inputs is not found, the alternative CWL will be assumed.

When submitting inputs with CWL job schema, plain key-value(s) pairs are expected. All values should be provided directly under the key (including arrays), except for File type that must include the class and path details.

Parameters
  • process_id – Identifier of the process to execute.

  • inputs – Literal JSON or YAML contents of the inputs submitted and inserted into the execution body, using either the OGC API - Processes or CWL format, or a file path/URL referring to them.

  • monitor – Automatically perform Job execution monitoring until completion or timeout to obtain final results. If requested, this operation will become blocking until either the completed status or timeout is reached.

  • timeout – Monitoring timeout (seconds) if requested.

  • interval – Monitoring interval (seconds) between job status polling requests.

  • url – Instance URL if not already provided during client creation.

Returns

Results of the operation.

upload(self: str, file_path: Optional[str], content_type: Optional[str] = None, url=None)OperationResult[source]

Upload a local file to the Vault.

Note

Feature only available for Weaver instances. Not available for standard OGC API - Processes.

See also

More details about formats and operations related to Vault are provided in File Vault Inputs and Uploading File to the Vault chapters.

Parameters
  • file_path – Location of the file to be uploaded.

  • content_type – Explicit Content-Type of the file. This should be an IANA Media-Type, optionally with additional parameters such as charset. If not provided, attempts to guess it based on the file extension.

  • url – Instance URL if not already provided during client creation.

Returns

Results of the operation.

status(self: str, job_reference: Optional[str], url=None)OperationResult[source]

Obtain the status of a Job.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • url – Instance URL if not already provided during client creation.

Returns

Retrieved status of the job.

monitor(self: str, job_reference: Optional[int], timeout: Optional[int] = None, interval: str = None, wait_for_status: Optional[str] = STATUS_SUCCEEDED, url=None)OperationResult[source]

Monitor the execution of a Job until completion.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • timeout – timeout (seconds) of maximum wait time for monitoring if completion is not reached.

  • interval – wait interval (seconds) between polling monitor requests.

  • wait_for_status – monitor until the requested status is reached (default: job failed or succeeded).

  • url – Instance URL if not already provided during client creation.

Returns

Result of the successful or failed job, or timeout of monitoring process.

results(self: str, job_reference: Optional[str], out_dir: bool = None, download: Optional[str] = False, url=None)OperationResult[source]

Obtain the results of a successful Job execution.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • out_dir – Output directory where to store downloaded files if requested (default: CURDIR/JobID/<outputs>).

  • download – Download any file reference found within results (CAUTION: could transfer lots of data!).

  • url – Instance URL if not already provided during client creation.

Returns

Result details and local paths if downloaded.

dismiss(self, job_reference, url=None)[source]

Dismiss pending or running Job, or clear result artifacts from a completed Job.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • url – Instance URL if not already provided during client creation.

Returns

Obtained result from the operation.

weaver.cli.setup_logger_from_options(logger: logging.Logger, args: argparse.Namespace)None[source]

Uses argument parser options to setup logging level from specified flags.

Setup both the specific CLI logger that is provided and the top-level package logger.

weaver.cli.make_logging_options(parser: argparse.ArgumentParser)None[source]

Defines argument parser options for logging operations.

weaver.cli.add_url_param(parser: argparse.ArgumentParser, required: bool = True)None[source]
weaver.cli.add_process_param(parser: argparse.ArgumentParser, description: Optional[str] = None, required: bool = True)None[source]
weaver.cli.add_job_ref_param(parser: argparse.ArgumentParser)None[source]
weaver.cli.add_timeout_param(parser: argparse.ArgumentParser)None[source]
weaver.cli.set_parser_sections(parser: argparse.ArgumentParser)None[source]
class weaver.cli.InputsFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Formatter for generating usage messages and argument help strings.

Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail.

_format_action(self, action)[source]

Override the returned help message with available options and shortcuts for inputs.

This ensures that paragraphs defined in the “inputs” argument’s help remain separated and properly formatted.

class weaver.cli.SubArgumentParserFixedMutexGroups(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]

Patch incorrectly handled mutually exclusive groups sections in subparsers.

_add_container_actions(self, container)[source]
class weaver.cli.ArgumentParserFixedRequiredArgs(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]

Override action grouping under ‘required’ section to consider explicit flag even if action has option prefix.

Default behaviour places option prefixed (-, --) arguments into optionals even if required is defined. Help string correctly considers this flag and doesn’t place those arguments in brackets ([--<optional-arg>]).

_add_action(self, action)[source]
class weaver.cli.WeaverArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]

Parser that provides fixes for proper representation of Weaver CLI arguments.

weaver.cli.make_parser()argparse.ArgumentParser[source]

Generate the CLI parser.

Note

Instead of employing argparse.ArgumentParser instances returned by argparse._SubParsersAction.add_parser(), distinct argparse.ArgumentParser instances are created for each operation and then merged back by ourselves as subparsers under the main parser. This provides more flexibility in arguments passed down and resolves, amongst other things, incorrect handling of exclusive argument groups and their grouping under corresponding section titles.

weaver.cli.main(*args: Any)int[source]