Exemplo n.º 1
0
    def __get_compile_cmds(self, task: Task, args: list):
        """
        Get compilation command to compile all of the task source files.

        :param task: related task
        :param args: additional arguments
        :return: list of compilation commands
        """
        compiler = task.get_compiler()
        if '' != compiler:
            bin_path = task.path_to_task_bin(self.__workdir)
            if not os.path.exists(bin_path):
                os.makedirs(bin_path)

            path = task.path_to_task_src(self.__workdir)
            if task.is_file_archive():
                if self.__cmake_handler is not None and task.uses_cmake():
                    if not self.__cmake_handler.is_cmake_target(path):
                        self.__cmake_handler.create_cmake_lists(task)
                    commands = self.__cmake_handler.get_compilation_commands_using_cmake(
                        task)
                else:
                    commands = self.__no_cmake_compile_cmd(
                        compiler, task, args)
            else:
                commands = self.__get_compile_cmd_for_single_file(
                    compiler, task, args)

            self.__log_writer.log(json.dumps(commands, indent=4),
                                  level=LogLevel.DEBUG)
            return commands
        else:
            raise RuntimeError('No compiler is set for the task: {}'.format(
                task.get_name()))
Exemplo n.º 2
0
    def __extract_path_files_and_zip_res(self, task: Task, zip_name: str):
        path = task.get_dir_name_for_task(self.workdir)

        if not os.path.exists(path):
            raise RuntimeError(
                'Cannot get files for task {}. No directory is present for this task.'
                .format(task.get_name()))

        files = os.listdir(path)
        zip_res = os.path.join(path, zip_name)
        return path, files, zip_res
Exemplo n.º 3
0
    async def recv_file(self, task: Task) -> Task:
        """
        Receive incoming file from the reader channel

        :param task: related task
        :return: task
        """
        bufsize = task.get_filesize()
        in_file = await self.__in_stream.read(bufsize)
        recv_name = task.get_name()

        await self.__io_handler.write_recvd_data(task, recv_name, in_file)

        return task
Exemplo n.º 4
0
    async def inform_client(self,
                            task: Task,
                            message: str,
                            error: Exception = None) -> None:
        """
        Send information to the server using async writer channel

        :param task: related task
        :param error: related error message
        :param message: message to send
        :return: nothing
        """
        to_send = {'task_info': {}, 'message': '', 'error': ''}

        if task is not None:
            # Add info about the received task
            task_msg = {
                'name': task.get_name(),
                'username': task.get_user(),
                'status': task.get_str_status()
            }
            to_send['task_info'] = task_msg

        to_send['message'] = message

        levelname = LogLevel.DEBUG
        if error is not None and error != 'None':
            error = '{}'.format(error)
            idx = error.find(self.__ERROR_DESC_START)
            if idx >= 0:
                error = error[idx + len(self.__ERROR_DESC_START):]

            to_send['error'] = '{}'.format(error)
            to_send['task_info']['status'] = 'ERROR'
            levelname = LogLevel.ERROR
        self.__log_writer.log('Request response: {}'.format(
            json.dumps(to_send, indent=4)),
                              level=levelname)

        try:
            # Sending response to CKD web application
            self.__out_stream.write(json.dumps(to_send, indent=4).encode())
            await self.__out_stream.drain()
        except Exception as e:
            self.__log_writer.log(
                'Error occurred while responding to the CKD application: {}'.
                format(e))
        self.__log_writer.log('Response sent.', level=LogLevel.DEBUG)
Exemplo n.º 5
0
    async def handle_compilation(self, task: Task, args: list):
        task.set_bin_name(
            os.path.join(task.path_to_task_bin(self.__workdir),
                         task.get_name() + '.out'))

        compilation_commands = self.__get_compile_cmds(task, args)

        compilation_output = await self.__executor.async_exec_cmds_with_wrapping(
            commands=compilation_commands,
            dir_to_use=task.path_to_task_bin(self.__workdir),
        )

        compilation_log_file = os.path.join(
            task.get_dir_name_for_task(self.__workdir), 'compilation.log')
        with open(compilation_log_file, 'w') as output_file:
            output_file.write(compilation_output)

        return
Exemplo n.º 6
0
    def create_cmake_lists(self, task: Task):
        """
        Generates CMakeLists.txt to make an archive into the CMake project

        :param task: task to handle
        :return: None
        """
        path = task.path_to_task_src(self.__workdir)
        cmake_lists_filename = os.path.join(path, self.__C_MAKE_LISTS_TXT__)

        main_file = self.__get_main_file_in_project(path)

        task_name = task.get_name()
        file_contents = [
            'cmake_minimum_required(VERSION {})'.format(self.__cmake_version),
            'project({})'.format(task_name),
            'SET(CMAKE_BUILD_TYPE Release)',
        ]

        extension = main_file.split('.')[-1]

        file_contents.append('file(GLOB SOURCES "./*.{}")'.format(extension))

        file_contents.append(' '.join(
            ['add_executable('.format(task_name), '${SOURCES})']))

        dirs = self.__filter_dirs(path)

        include_dirs = list(filter(lambda x: 'include' in x, dirs))
        include_dirs = set(include_dirs)

        file_contents.append('include_directories({})'.format(
            ', '.join(include_dirs)))

        dirs = set(dirs) - include_dirs

        for dir_name in dirs:
            file_contents.append('add_subdirectory({})'.format(dir_name))

        file_contents = '\n'.join(file_contents)
        file_contents = correct_line_breaks(file_contents)

        with open(cmake_lists_filename, 'w') as cmake_lists_file:
            cmake_lists_file.write(file_contents)
Exemplo n.º 7
0
    def __init_templ_dct(self, templ_dct, task: Task):
        """
        Function to initialize template dictionary with methods of the related Task object

        :param task: related task
        :return: nothing
        """
        templ_dct['__procnum__'] = task.get_procnum()
        templ_dct['__walltime__'] = task.get_walltime()
        templ_dct['__memory__'] = task.get_memory()
        templ_dct['__filename__'] = task.get_filename()
        templ_dct['__descname__'] = task.get_passport_name()
        templ_dct['__jobid__'] = task.get_jobid()
        templ_dct['__name__'] = task.get_name()
        templ_dct['__user__'] = task.get_user()
        templ_dct['__taskdir__'] = task.get_dir_name_for_task(self.workdir)
        templ_dct['__binname__'] = task.get_bin_name()
        templ_dct['__logname__'] = task.get_log_name()
        templ_dct['__workdir__'] = self.__get_workdir()