Esempio n. 1
0
    def get_response_and_status_impl(self, request):
        file_path = request.file_path
        response = FileViewerRPCResponse()
        if FileUtil.is_file(path_name=file_path):
            file_name = FileUtil.die_if_file_not_exist(file_name=file_path)
            file_info = response.files_info.add()
            file_info.file_path = file_name
            file_info.file_size = FileUtil.get_file_size(file_name=file_name)
            file_info.modified_time = str(
                FileUtil.get_file_modified_time(file_name=file_name))
        else:
            dir_name = FileUtil.die_if_dir_not_exist(dir_name=file_path)
            sub_files = FileUtil.list_files_in_dir(dir_name=dir_name)
            for sub_file in sub_files:
                file_info = response.files_info.add()
                file_info.file_path = sub_file
                file_info.file_size = FileUtil.get_file_size(
                    file_name=sub_file)
                file_info.modified_time = str(
                    FileUtil.get_file_modified_time(file_name=sub_file))
            sub_dirs = FileUtil.list_dirs_in_dir(dir_name=dir_name)
            for sub_dir in sub_dirs:
                dirs_info = response.directories_info.add()
                dirs_info.file_path = sub_dir

        return response, Status.SUCCEEDED
Esempio n. 2
0
 def get_content_from_snapshot(cls, snapshot_file, message_type=OperatorContentPlain):
     try:
         snapshot = FileUtil.read_proto_from_file(
             proto_type=OperatorSnapshot,
             file_name=FileUtil.die_if_file_not_exist(file_name=snapshot_file)
         )
         return cls.content_deserializer(content=snapshot.content)
     except FileNotExistException as _:
         return message_type()
Esempio n. 3
0
 def get_status_from_snapshot(cls, snapshot_file):
     try:
         snapshot = FileUtil.read_proto_from_file(
             proto_type=OperatorSnapshot,
             file_name=FileUtil.die_if_file_not_exist(file_name=snapshot_file)
         )
         return snapshot.status
     except FileNotExistException as _:
         return Status.IDLE
Esempio n. 4
0
 def get_content_from_snapshot(cls, snapshot_file, message_type):
     try:
         with FileLockTool(snapshot_file, read_mode=True):
             snapshot = FileUtil.read_proto_from_file(
                 proto_type=OperatorSnapshot,
                 file_name=FileUtil.die_if_file_not_exist(file_name=snapshot_file)
             )
         return ProtoUtil.any_to_message(message_type=message_type, any_message=snapshot.content)
     except FileNotExistException as _:
         return message_type()
Esempio n. 5
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
Esempio n. 6
0
from flask_login import login_required
from pslx.micro_service.frontend import pslx_frontend_ui_app, pslx_frontend_logger
from pslx.micro_service.proto_viewer.client import ProtoViewerRPCClient
from pslx.util.file_util import FileUtil


client_map = {}

server_urls = []
for server_config in pslx_frontend_ui_app.config['frontend_config'].proto_viewer_config:
    url = server_config.server_url
    certificate_path = server_config.root_certificate_path
    pslx_frontend_logger.info("Proto viewer Getting url [" + url + "] and certificate path [" + certificate_path + '].')
    root_certificate = None
    if certificate_path:
        with open(FileUtil.die_if_file_not_exist(file_name=certificate_path), 'r') as infile:
            root_certificate = infile.read()

    proto_viewer_client = ProtoViewerRPCClient(
        server_url=url
    )
    client_map[url] = {
        'client': proto_viewer_client,
        'root_certificate': root_certificate,
    }
    server_urls.append(url)


@pslx_frontend_ui_app.route('/proto_viewer.html', methods=['GET', 'POST'])
@pslx_frontend_ui_app.route('/view_proto', methods=['GET', 'POST'])
@login_required