hbp_nrp_backend.storage_client_api.StorageClient module

Wrapper around the storage API

class Model(nameModel, typeModel, pathModel=None)[source]

Bases: object

This class represents the model that we have in the model DB.

class ModelType[source]

Bases: object

Enumeration for model types. Model resources are enhanced in a different structure

static getResourceType(value)[source]

returns the key of the valueToFind form the types dictionary.

types = {<ResourceType.ROBOT: 286261250>: 'robots', <ResourceType.ENVIRONMENT: 286261253>: 'environments', <ResourceType.BRAIN: 286261251>: 'brains'}
class StorageClient[source]

Bases: object

Wrapper around the storage server API. Users of this class should first call the authentication function to retrieve a token, before making the requests to the storage server

can_acess_experiment(token, context_id, experiment_id)[source]

Verifies if an authenticated user can access an experiment

Parameters
  • token – The authentication token

  • context_id – Optional context idenfifier

  • experiment_id – The experiment id

Returns

Whether the user can access the experiment

check_file_extension(filename, extensions)[source]

checks if an file is of a certain extension

Parameters
  • filename – the file name

  • extensions – the extensions list to check

clone_all_experiment_files(token, experiment, destination_dir=None, exclude=[])[source]

Clones all the experiment files to a simulation folder. The caller has then the responsibility of managing this folder.

Parameters
  • token – The token of the request

  • experiment – The experiment to clone

  • destination_dir – the directory in which to clone the files, if None is provided, clones in a temporary folder

  • exclude – a list of folders of files not to clone (folder names ends with ‘/’)

Returns

A dictionary containing the paths to the experiment files

clone_file(filename, token, experiment)[source]

Clones a file according to a given filename to a simulation folder. The caller then has the responsibility of managing this folder.

Parameters
  • filename – The filename of the file to clone

  • token – The token of the request

  • experiment – The experiment which contains the file

Returns

The local path of the cloned file,

copy_file_content(token, src_folder, dest_folder, filename)[source]

copy the content of file located in the Storage into the proper tmp folder

Parameters
  • token – The token of the request

  • src_folder – folder location where it will be copy from

  • dest_folder – folder location where it will be copy to

  • filename – name of the file to be copied.

copy_folder_content_to_tmp(token, folder)[source]

copy the content of the folder located in storage/experiment into sim_dir folder

Parameters
  • token – The token of the request

  • folder – the folder in the storage folder to copy in tmp folder, it has included the uuid of the experiment

copy_resources_folder(token, experiment)[source]

Copy the resources folder located in storage/experiment into simulation folder

Parameters
  • token – The token of the request

  • experiment – The experiment which contains the resource folder

create_and_extract_zip(token, experiment, name, content)[source]

Creates and extracts a zip under an experiment.

allow the transfer of multiple files. For instance we might add a create_files(files_list) in StorageClient. Internally, the files might be zipped on the client and unzipped on the server.

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • name – the name of the zip

  • content – the content of the file

create_folder(token, experiment, name)[source]

Creates a folder under an experiment. If the folder exists we reuse it

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • name – the name of the folder to create

create_material_from_textures(textures)[source]

Algorithm to create a new material from the textures. For every texture we append a new default material which points to the texture.

create_or_update(token, experiment, filename, content, content_type, append=False)[source]

Creates or updates a file under an experiment

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • filename – the name of the file to update/create

  • content – the content of the file

  • content_type – the content type of the file i.e. text/plain or application/octet-stream

  • append – append to file or create new file

create_textures_paths()[source]

Generate the folder structure under assets. Looks like: relative_path/materials/scripts/custom.material relative_path/materials/textures/texture1…n

delete_file(token, experiment, filename)[source]

Deletes a file under under an experiment based on the experiment name and the filename. Needs the user token

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • filename – the name of the file to delete

Returns

if successful, the name of the deleted file

static filter_textures(textures)[source]

Returns only the textures from /resources/textures

generate_textures(experiment, token)[source]

Clones all the contents of the textures folders to the temporary directory and creates the structure required by gazebo and gzweb.

Parameters
  • token – The token of the request

  • experiment – The experiment which contains the textures folder

get_file(token, experiment, filename, by_name=False)[source]

Gets the content of a file under an experiment based on the filename and on the filetype

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • filename – the name of the file to return

Returns

if successful, the content of the file as a binary string

get_files_list(token, experiment, folder=None)[source]

Lists all the files under an experiment based on the experiment name and the user token

Parameters
  • token – a valid token to be used for the request

  • experiment – the name of the experiment

  • folder – it is a boolean variable that indicates if get_files_list returns folders or not.

Returns

if successful, the files under the experiment

get_folder_uuid_by_name(token, context_id, folder_name)[source]

Returns the uuid of a folder provided its name

Parameters
  • token – a valid token to be used for the request

  • context_id – the context_id of the collab

  • folder_name – the name of the folder

Returns

if found, the uuid of the named folder

get_model(token, context_id, model)[source]

Returns the content of a custom model file

Parameters
  • token – a valid token to be used for the request

  • context_id – the context_id of the collab

  • model – the model object, check class Model

Returns

if found, returns the content of the model as a binary string

get_model_path(token, context_id, model)[source]

Returns the path to a custom model

Parameters
  • token – a valid token to be used for the request

  • context_id – the context_id of the collab

  • model – model object, check class Model

Returns

if found, the uuid of the named folder

get_models_list(token, context_id, model_type)[source]

Returns a list with custom models of a certain model_type

Parameters
  • token – a valid token to be used for the request

  • context_id – the context_id of the collab

  • model_type – the type of the model defined in ModelType

Returns

if found, list of Models objects

get_textures_list(experiment, token)[source]

Returns the contents of the resources/textures experiment folder

Parameters
  • experiment – the name of the experiment

  • token – a valid token to be used for the request

Returns

if found, the list of textures

get_user(token)[source]

Retrieves the user id for the specified authentication token

Parameters

token – the authentication token

Returns

the user id

list_experiments(token, context_id, get_all=False, name=None)[source]

Lists the experiments the user has access to depending on his token

Parameters
  • token – a valid token to be used for the request

  • context_id – the context_id if we are using collab storage

  • get_all – a parameter to return all the available experiments, not only the ones available to a specific user

  • name – if we want to get a specific folder i.e. the robots

Returns

an array of all the available to the user experiments

static parse_and_check_file_is_valid(filepath, create_obj_function, instance_type)[source]

Parses a file and checks if it corresponds to its instance type and can be created into its object

Parameters
  • filepath – The path of the file

  • create_obj_function – The function to create the object

  • instance_type – The required instance type of the file

Returns

An object containing the file content

set_sim_dir(sim_dir)[source]

Sets the sim_dir for this client

Parameters

sim_dir – Simulation directory