Ejemplo n.º 1
0
    def create_course(self, courseid, init_content):
        """
        :param courseid: the course id of the course
        :param init_content: initial descriptor content
        :raise InvalidNameException or CourseAlreadyExistsException
        Create a new course folder and set initial descriptor content, folder can already exist
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)

        course_fs = self.get_course_fs(courseid)
        course_fs.ensure_exists()

        if course_fs.exists("course.yaml") or course_fs.exists("course.json"):
            raise CourseAlreadyExistsException("Course with id " + courseid +
                                               " already exists.")
        else:
            course_fs.put("course.yaml",
                          get_json_or_yaml("course.yaml", init_content))

        get_course_logger(courseid).info("Course %s created in the factory.",
                                         courseid)
        self._hook_manager.call_hook('course_created',
                                     courseid=courseid,
                                     new_content=init_content)
Ejemplo n.º 2
0
    def create_course(self, courseid, init_content):
        """
        :param courseid: the course id of the course
        :param init_content: initial descriptor content
        :raise InvalidNameException or CourseAlreadyExistsException
        Create a new course folder and set initial descriptor content, folder can already exist
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)

        course_directory = os.path.join(self._tasks_directory, courseid)
        if not os.path.exists(course_directory):
            os.mkdir(course_directory)

        base_file = os.path.join(course_directory, "course")
        if not os.path.isfile(base_file +
                              ".yaml") and not os.path.isfile(base_file +
                                                              ".json"):
            write_yaml(os.path.join(course_directory, "course.yaml"),
                       init_content)
        else:
            raise CourseAlreadyExistsException("Course with id " + courseid +
                                               " already exists.")

        get_course_logger(courseid).info("Course %s created in the factory.",
                                         courseid)
Ejemplo n.º 3
0
 def create_course(self, templateid, init_content, init_description=None):
     """
     :param init_description: initial template descriptor content
     :param templateid: the course id of the course
     :param init_content: initial descriptor content
     :param init_description: initial description of the template
     :raise InvalidNameException or CourseAlreadyExistsException
     Create a new course folder and set initial descriptor content, folder can already exist
     Set initial template description
     """
     super().create_course(templateid, init_content)
     template_fs = self.get_course_fs(templateid)
     if template_fs.exists("template.yaml"):
         raise CourseAlreadyExistsException("Template with id " +
                                            templateid + " already exists.")
     else:
         template_fs.put(
             "template.yaml",
             get_json_or_yaml("template.yaml", init_description))