Exemple #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
Exemple #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