def view_proto_table():
    value_types = EnvUtil.get_all_schemas(
        pslx_frontend_ui_app.config['schemas'])
    if request.method == 'POST':
        try:
            proto_table_path = request.form['proto_table_path'].strip()
            selected_value_type = request.form['value_type'].strip()
            modules = selected_value_type.split('.')
            module, value_type = '.'.join(modules[:-1]), modules[-1]
            pslx_frontend_logger.info("Proto table viewer input path [" +
                                      proto_table_path +
                                      '] with value type [' + value_type +
                                      '] in module name [' + module + '].')
            result = FileUtil.read_proto_from_file(proto_type=ProtoTable,
                                                   file_name=proto_table_path)
            value_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=value_type, modules=module)
            proto_contents = []
            result_content = dict(result.data)
            for key in sorted(result_content.keys()):
                proto_val = ProtoUtil.any_to_message(
                    message_type=value_type, any_message=result_content[key])
                try:
                    proto_contents.append({
                        'key':
                        key,
                        'val':
                        ProtoUtil.message_to_text(proto_message=proto_val),
                    })
                except Exception as err:
                    pslx_frontend_logger.error(
                        "Proto table viewer Parsing proto with error " +
                        str(err) + '.')
                    proto_contents.append({
                        'key': key,
                        'val': str(proto_val),
                    })
            value_types.remove(selected_value_type)
            return render_template('proto_table_viewer.html',
                                   proto_contents=proto_contents,
                                   value_types=value_types,
                                   selected_value_type=selected_value_type)
        except Exception as err:
            pslx_frontend_logger.error(
                "Got error rendering proto_table_viewer.html: " + str(err) +
                '.')
            return render_template('proto_table_viewer.html',
                                   proto_contents=[],
                                   value_types=value_types,
                                   selected_value_type='')
    else:
        return render_template('proto_table_viewer.html',
                               proto_contents=[],
                               value_types=value_types,
                               selected_value_type='')
Ejemplo n.º 2
0
 def get_response_and_status_impl(self, request):
     proto_file = FileUtil.die_if_file_not_exist(
         file_name=request.proto_file_path)
     message_type = ProtoUtil.infer_message_type_from_str(
         message_type_str=request.message_type,
         modules=request.proto_module if request.proto_module else None)
     response = ProtoViewerRPCResponse()
     proto_message = FileUtil.read_proto_from_file(proto_type=message_type,
                                                   file_name=proto_file)
     response.proto_content = ProtoUtil.message_to_text(
         proto_message=proto_message)
     file_info = FileInfo()
     file_info.file_path = request.proto_file_path
     file_info.file_size = FileUtil.get_file_size(file_name=proto_file)
     file_info.modified_time = str(
         FileUtil.get_file_modified_time(file_name=proto_file))
     response.file_info.CopyFrom(file_info)
     return response, Status.SUCCEEDED
Ejemplo n.º 3
0
def view_proto():
    value_types = EnvUtil.get_all_schemas(pslx_frontend_ui_app.config['schemas'])
    if request.method == 'POST':
        try:
            proto_file_path = request.form['proto_file_path'].strip()
            selected_value_type = request.form['value_type'].strip()
            modules = selected_value_type.split('.')
            module, message_type_str = '.'.join(modules[:-1]), modules[-1]
            pslx_frontend_logger.info("Proto viewer input path [" + proto_file_path + '] with message type [' +
                                      message_type_str + '] in module name [' + module + '].')
            message_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=message_type_str,
                modules=module
            )
            proto_message = FileUtil.read_proto_from_file(
                proto_type=message_type, file_name=proto_file_path)

            result_ui = ProtoUtil.message_to_text(proto_message=proto_message)

            return render_template(
                'proto_viewer.html',
                proto_content=result_ui,
                value_types=value_types,
                selected_value_type=selected_value_type
            )
        except Exception as err:
            pslx_frontend_logger.error("Got error rendering proto_viewer.html: " + str(err) + '.')
            return render_template(
                'proto_viewer.html',
                proto_content="Got error rendering proto_viewer.html: " + str(err) + '.',
                value_types=value_types,
                selected_value_type=''
            )
    else:
        return render_template(
            'proto_viewer.html',
            proto_content="",
            value_types=value_types,
            selected_value_type=''
        )
Ejemplo n.º 4
0
def view_proto_table():
    all_urls = sorted(server_urls)
    if request.method == 'POST':
        try:
            server_url = request.form['server_url'].strip()
            proto_table_path = request.form['proto_table_path'].strip()
            value_type = request.form['value_type'].strip()
            module = request.form['module'].strip()
            pslx_frontend_logger.info("Proto table viewer selecting url [" + server_url + '] and input path [' +
                                      proto_table_path + '] with value type [' + value_type +
                                      '] in module name [' + module + '].')
            result = client_map[server_url]['client'].view_proto(
                proto_file_path=proto_table_path,
                message_type="ProtoTable",
                module="",
                root_certificate=client_map[server_url]['root_certificate']
            )
            value_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=value_type,
                modules=module
            )
            result_content = ProtoUtil.text_to_message(message_type=ProtoTable, text_str=result['proto_content'])
            proto_contents = []
            result_content = dict(result_content.data)
            for key in sorted(result_content.keys()):
                proto_val = ProtoUtil.any_to_message(
                    message_type=value_type,
                    any_message=result_content[key]
                )
                try:
                    proto_contents.append(
                        {
                            'key': key,
                            'val': ProtoUtil.message_to_text(proto_message=proto_val),
                        }
                    )
                except Exception as err:
                    pslx_frontend_logger.error("Proto table viewer Parsing proto with error " + str(err) + '.')
                    proto_contents.append(
                        {
                            'key': key,
                            'val': str(proto_val),
                        }
                    )

            all_urls.remove(server_url)
            all_urls = [server_url] + all_urls
            return render_template(
                'proto_table_viewer.html',
                proto_contents=proto_contents,
                server_urls=all_urls
            )
        except Exception as err:
            pslx_frontend_logger.error("Got error rendering proto_table_viewer.html: " + str(err) + '.')
            return render_template(
                'proto_table_viewer.html',
                proto_contents=[],
                server_urls=all_urls
            )
    else:
        return render_template(
            'proto_table_viewer.html',
            proto_contents=[],
            selected_server_url='',
            server_urls=server_urls
        )