Beispiel #1
0
def menu_push(request, resource_object, parent):
    try:
        response_sub_resource = resource_object.post(request)
        request['id'] = response_sub_resource.id
        if parent and parent.name == "Software Version":
            variable_selected = "models"
            response_get_parent = parent.get()
            resources = get_label_from_response(response_get_parent)
            print_choices(resources)
            if click.confirm("Did you find the {}?".format(variable_selected), default=True):
                choice = click.prompt("Select the {}".format(variable_selected),
                                      default=1,
                                      show_choices=False,
                                      type=click.Choice(list(range(1, len(resources) + 1))),
                                      value_proc=parse
                                      )
                model_version = response_get_parent[choice - 1]
                if model_version.has_configuration:
                    model_version.has_configuration.append({"id":response_sub_resource.id})
                else:
                    model_version.has_configuration = [{"id":response_sub_resource.id}]

                parent.put(model_version)
        click.secho(f"Success", fg="green")
    except ApiException:
        click.secho(f"An error occurred when sending the request", fg="red")
Beispiel #2
0
def menu_edit_resource_complex(request,
                               variable_selected,
                               mapping,
                               resource_object,
                               full_request=None):
    """
    Call to the menu to create the resource complex
    @param resource_object:
    @type resource_object:
    @param request: request
    @type request: dict
    @param variable_selected: The name of variable selected (mic spec). For example: Versions
    @type variable_selected: string
    @param mapping: Mapping of the resource
    @type mapping: dict
    """
    labels = get_label_from_response(request)
    print_choices(labels)
    choice = click.prompt("Select the resource to edit",
                          default=1,
                          show_choices=False,
                          type=click.Choice(list(range(1,
                                                       len(labels) + 1))),
                          value_proc=parse)
    request_var = get_prop_mapping(mapping, variable_selected)
    call_edit_resource(request, mapping, variable_selected, request_var,
                       resource_object, full_request)
Beispiel #3
0
def menu_select_existing_resources(resource_object, request_property,
                                   variable_selected):
    """
    Menu: Show the existing resources and asks to user the selection
    @param variable_selected: The name of variable selected (mic spec). For example: Versions
    @type variable_selected: string
    @return: A resource
    @rtype: dict
    """
    click.echo("Available resources")
    sub_resource_object = getattr(resource_object, request_property)
    sub_resource_mapping, sub_resource = sub_resource_object[
        "mapping"], sub_resource_object["resource"]
    response = sub_resource.get()
    resources = get_label_from_response(response)
    print_choices(resources)
    if click.confirm("Did you find the {}?".format(variable_selected),
                     default=True):
        choice = click.prompt("Select the {}".format(variable_selected),
                              default=1,
                              show_choices=False,
                              type=click.Choice(
                                  list(range(1,
                                             len(resources) + 1))),
                              value_proc=parse)
        return response[choice - 1].to_dict()
    return None
Beispiel #4
0
def menu_delete_resource_complex(request):
    """
    Menu: asks the resource to delete
    @param request: request
    @type request: dict
    """
    labels = get_label_from_response(request)
    print_choices(labels)
    choice = click.prompt("Select the resource to delete",
                          default=1,
                          show_choices=False,
                          type=click.Choice(list(range(1, len(labels) + 1))),
                          value_proc=parse
                          )
    if not isinstance(choice, int):
        show_error("Please only input integers not characters.")
        menu_delete_resource_complex(request)
    elif choice > 0 and choice <= len(labels):
        request.pop(choice - 1)
    else:
        show_error("The current value for choice is either greater than length of input size or less than equal to zero.")
        menu_delete_resource_complex(request)
Beispiel #5
0
def get_show_models(resources, resource_name):
    labels = get_label_from_response(resources)
    click.secho("Existing {} are:".format(resource_name))
    print_choices(labels)
    return labels
Beispiel #6
0
def get_show_models_version(resources, software_version_cli):
    labels = get_label_from_response(
        [software_version_cli.get_one(obtain_id(i.id)) for i in resources])
    click.secho("Existing versions are:")
    print_choices(labels)
    return labels