cookbase.schema

Module contents

Package for handling Cookbase Schema builds.

Submodules

cookbase.schema.builder

Cookbase Schema Builder

This module processes Cookbase Schema templates and compiles them into the desired directory structure, either on a local or remote (through SSH) location.

The configuration is taken by default from the build-config.yaml file, having the option to provide a custom configuration file by using the -c/--config command-line option. Any mandatory parameters lacking in the custom coniguration file are directly taken from the default values.

class cookbase.schema.builder._SSHConnection(hostname: str = None, port: int = None, username: str = None)[source]

Bases: object

Helper class handling SFTP communication.

If provided with a hostname, automatically initiates the SFTP session.

Parameters:
  • hostname (str, optional) – The SSH host, defaults to None
  • port (int, optional) – The port where the SSH host is listening, defaults to None
  • username (str, optional) – The username on the target SSH host, defaults to None
Variables:
  • client (paramiko.client.SSHClient) – The SSH session handler
  • sftp_session (paramiko.sftp_client.SFTPClient) – The SFTP session handler
client = None
close_session()[source]

Closes the SFTP session.

is_active()[source]

Checks whether the SSH session is active or not.

mkdir_p(path: str)[source]

Simulates the mkdir -p <path> Unix command, making a directory and all its non-existing parent directories.

Parameters:path (str) – The path to a directory
set_session(hostname: str, port: int = None, username: str = None)[source]

Sets up a SFTP session.

Parameters:
  • hostname (str) – The SSH host
  • port (int, optional) – The port where the SSH host is listening, defaults to None
  • username (str, optional) – The username on the target SSH host, defaults to None
sftp_session = None
write_file(s: str, path: str)[source]

Creates or overwrites a file under path and stores the content of s in it.

Parameters:
  • s (str) – String to be written into a new file
  • path – Path to the new file
cookbase.schema.builder.build_abs_schema_uri(rel_path: str)[source]

It forms an absolute URI from a relative path considering the common.cb_schemas_base_url property provided by the build configuration file.

Parameters:rel_path (str) – A path relative to build_params.root_build_dir
Returns:An absolute URI intended to unambiguously refer to the given path
Return type:str
cookbase.schema.builder.build_caf_schema()[source]

Builds the CAF Schema according to the provided configuration.

cookbase.schema.builder.build_cb_common_definitions_schema()[source]

Builds the CB Common Definitions Schema according to the provided configuration.

cookbase.schema.builder.build_cba_schema()[source]

Builds the CBA Schema according to the provided configuration.

cookbase.schema.builder.build_cbi_schema()[source]

Builds the CBI Schema according to the provided configuration.

cookbase.schema.builder.build_cbp_schema()[source]

Builds the CBP Schema according to the provided configuration.

cookbase.schema.builder.build_cbr_process_definitions_schema()[source]

Builds the CBR Process Definitions Schema according to the provided configuration.

cookbase.schema.builder.build_cbr_process_schema(do_collection: bool = True)[source]

Builds the CBR Process Schema according to the provided configuration.

If the do_collection flag is set to True (the default), the function will builds CBR Process Schemas collection.

Parameters:do_collection (bool, optional) – Flag indicating whether the CBR Process Schemas collection will be generated or not.
cookbase.schema.builder.build_cbr_schema(build_cbr_process: bool = True)[source]

Builds the CBR Schema according to the provided configuration.

If the build_cbr_process flag is set to True (the default), this function will also build CBR Process Schema.

Parameters:build_cbr_process (bool, optional) – Flag indicating whether the CBR Process Schema will be generated or not
cookbase.schema.builder.build_rel_path(start_rel_path: str, target_rel_path: str)[source]

Calculates the relative path from start_rel_path to target_rel_path.

Parameters:
  • start_rel_path (str) – The startpoint path
  • target_rel_path (str) – The target path
Returns:

A relative path from start_rel_path to target_rel_path

Return type:

str

cookbase.schema.builder.closedown()[source]

Terminates the builder.

cookbase.schema.builder.generate_cbr_process_collection()[source]

Generates and writes into files the CBR Process Schemas from a collection of CBP files.

The accessed CBP files are under the directory specified by the cbr_process.cbp_dir property from the build configuration file.

The routes to the JSON Schema definitions of the different types referred by the CBP documents are detailed in the configuration file under the path given by the cbr_process.types_path property.

cookbase.schema.builder.generate_cbr_process_collection_item(cbp: Dict[str, Any], defs: Dict[str, str], schema_filename: str = None)[source]

Generates and writes into a file a CBR Process Schema from a CBP document.

If schema_filename is set to None (the default), the output file name will be assumed to be the first English name given in the CBP’s name property, lowercased, substituted spaces by underscores _, and appended the .json extension.

Parameters:
  • cbp (dict[str, Any]) – The dictionary representing the content of a CBP document
  • defs (dict[str, str]) – A dictionary mapping the CBP data.schema.foodstuffKeywords.*.type properties to the location of its definition
  • schema_filename (str, optional) – The name of the file where the CBP is to be stored, defaults to None
cookbase.schema.builder.generate_cbr_process_main_schema()[source]

Generates and writes into file the CBR Process Main Schema from a collection of CBR Process Schemas.

Its path is provided by the cbr.cbr_process_path property in the build configuration file.

cookbase.schema.builder.init(config_path: str = None)[source]

Initializes the builder.

If a custom build configuration file config_path is not provided, the default build configuration is loaded; if provided, any lacking parameter will be completed with the default configuration.

In case of a build_params.root_build_dir configuration property consisting of a SSH or SFTP URI, a SFTP session with the target host is opened.

Parameters:config_path (str, optional) – Path to the custom build configuration file, defaults to None
cookbase.schema.builder.render(template_filename: str, schema_path: str, substs: Dict[str, str])[source]

Creates a JSON Schema file under schema_path from applying the substitutions substs to a template stored in template_filename.

Parameters:
  • template_filename (str) – The name of the template file to be rendered
  • schema_path (str) – The path where the generated JSON Schema will be stored
  • substs (Dict[str, str]) – A dictionary including the substitutions to be performed on the template
cookbase.schema.builder.write_to_file(s: str, path: str)[source]

Creates or overwrites a file (either locally or remotely) and stores s in it.

Parameters:
  • s (str) – The string to be written in the file
  • path (str) – The path where the file is to be created