Example #1
0
    def update_temporal_task_file(self, course, taskid, data):
        """
        :param course: a Course object
        :param taskid: the task id of the task
        :param data: a Dict with the temporary data of the task to be stored
        :raise InvalidNameException, TaskReaderNotFoundException, TaskNotFoundException
      
        Create or Update a temporary task file that is used to store the task data that is required for some plugins
        """
        if not id_checker(taskid):
            raise InvalidNameException("Task with invalid name: " + taskid)

        task_fs = self.get_task_fs(course.get_id(), taskid)

        task_file_manager = None

        try:
            for file_extension, file_manager in self._task_file_managers.items(
            ):
                if file_extension is "yaml":
                    task_file_manager = file_manager

        except:
            raise TaskReaderNotFoundException()

        if task_file_manager:
            temporal_task_file_content = task_file_manager.dump(data)

        try:
            task_fs.put("task_temp.yaml", temporal_task_file_content)
        except:
            raise TaskNotFoundException()
Example #2
0
    def update_task_descriptor_content(self,
                                       courseid,
                                       taskid,
                                       content,
                                       force_extension=None):
        """
        Update the task descriptor with the dict in content
        :param course: the course id of the course
        :param taskid: the task id of the task
        :param content: the content to put in the task file
        :param force_extension: If None, save it the same format. Else, save with the given extension
        :raise InvalidNameException, TaskNotFoundException, TaskUnreadableException
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)
        if not id_checker(taskid):
            raise InvalidNameException("Task with invalid name: " + taskid)

        if force_extension is None:
            path_to_descriptor, _, descriptor_manager = self._get_task_descriptor_info(
                courseid, taskid)
        elif force_extension in self.get_available_task_file_extensions():
            path_to_descriptor = os.path.join(self._tasks_directory, courseid,
                                              taskid,
                                              "task." + force_extension)
            descriptor_manager = self._task_file_managers[force_extension]
        else:
            raise TaskReaderNotFoundException()

        try:
            with codecs.open(path_to_descriptor, 'w', 'utf-8') as fd:
                fd.write(descriptor_manager.dump(content))
        except:
            raise TaskNotFoundException()
Example #3
0
    def update_task_descriptor_content(self,
                                       courseid,
                                       taskid,
                                       content,
                                       force_extension=None):
        """
        Update the task descriptor with the dict in content
        :param courseid: the course id of the course
        :param taskid: the task id of the task
        :param content: the content to put in the task file
        :param force_extension: If None, save it the same format. Else, save with the given extension
        :raise InvalidNameException, TaskNotFoundException, TaskUnreadableException
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)
        if not id_checker(taskid):
            raise InvalidNameException("Task with invalid name: " + taskid)

        if force_extension is None:
            path_to_descriptor, descriptor_manager = self._get_task_descriptor_info(
                courseid, taskid)
        elif force_extension in self.get_available_task_file_extensions():
            path_to_descriptor = "task." + force_extension
            descriptor_manager = self._task_file_managers[force_extension]
        else:
            raise TaskReaderNotFoundException()

        try:
            self.get_task_fs(courseid,
                             taskid).put(path_to_descriptor,
                                         descriptor_manager.dump(content))
        except:
            raise TaskNotFoundException()

        self._hook_manager.call_hook('task_updated',
                                     courseid=courseid,
                                     taskid=taskid,
                                     new_content=content)