Пример #1
0
    def _cache_update_needed(self, courseid):
        """
        :param courseid: the (valid) course id of the course
        :raise InvalidNameException, CourseNotFoundException
        :return: True if an update of the cache is needed, False else
        """
        if courseid not in self._cache:
            return True

        try:
            descriptor_name = self._get_course_descriptor_path(courseid)
            last_update = {
                descriptor_name:
                self._filesystem.get_last_modification_time(descriptor_name)
            }
            translations_fs = self._filesystem.from_subfolder("$i18n")
            if translations_fs.exists():
                for f in translations_fs.list(folders=False,
                                              files=True,
                                              recursive=False):
                    lang = f[0:len(f) - 3]
                    if translations_fs.exists(lang + ".mo"):
                        last_update[
                            "$i18n/" + lang +
                            ".mo"] = translations_fs.get_last_modification_time(
                                lang + ".mo")
        except:
            raise CourseNotFoundException()

        last_modif = self._cache[courseid][1]
        for filename, mftime in last_update.items():
            if filename not in last_modif or last_modif[filename] < mftime:
                return True

        return False
Пример #2
0
 def _get_course_descriptor_path(self, courseid):
     """
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException
     :return: the path to the descriptor of the course
     """
     if not id_checker(courseid):
         raise InvalidNameException("Course with invalid name: " + courseid)
     course_fs = self.get_course_fs(courseid)
     if course_fs.exists("course.yaml"):
         return courseid + "/course.yaml"
     if course_fs.exists("course.json"):
         return courseid + "/course.json"
     raise CourseNotFoundException()
Пример #3
0
 def _get_template_descriptor_path(self, courseid):
     """
     [Source code integration]: generalise with get_course_descriptor_path
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException
     :return: the path to the description of the template
     """
     if not id_checker(courseid):
         raise InvalidNameException("Template with invalid name: " +
                                    courseid)
     course_fs = self.get_course_fs(courseid)
     if course_fs.exists("template.yaml"):
         return courseid + "/template.yaml"
     raise CourseNotFoundException()
Пример #4
0
 def _get_course_descriptor_path(self, courseid):
     """
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException
     :return: the path to the descriptor of the course
     """
     if not id_checker(courseid):
         raise InvalidNameException("Course with invalid name: " + courseid)
     base_file = os.path.join(self._tasks_directory, courseid, "course")
     if os.path.isfile(base_file + ".yaml"):
         return base_file + ".yaml"
     elif os.path.isfile(base_file + ".json"):
         return base_file + ".json"
     else:
         raise CourseNotFoundException()
Пример #5
0
    def _cache_update_needed(self, courseid):
        """
        :param courseid: the (valid) course id of the course
        :raise InvalidNameException, CourseNotFoundException
        :return: True if an update of the cache is needed, False else
        """
        if courseid not in self._cache:
            return True

        try:
            last_update = os.stat(self._get_course_descriptor_path(courseid)).st_mtime
        except:
            raise CourseNotFoundException()

        if self._cache[courseid][1] < last_update:
            return True
Пример #6
0
    def delete_course(self, courseid):
        """
        :param courseid: the course id of the course
        :raise InvalidNameException or CourseNotFoundException
        Erase the content of the course folder
        """
        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):
            raise CourseNotFoundException()

        shutil.rmtree(course_directory)

        get_course_logger(courseid).info("Course %s erased from the factory.", courseid)
Пример #7
0
    def delete_course(self, courseid):
        """
        :param courseid: the course id of the course
        :raise InvalidNameException or CourseNotFoundException
        Erase the content of the course folder
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)

        course_fs = self.get_course_fs(courseid)

        if not course_fs.exists():
            raise CourseNotFoundException()

        course_fs.delete()

        get_course_logger(courseid).info("Course %s erased from the factory.",
                                         courseid)
def get_marketplace_course(courseid):
    courses = get_all_marketplace_courses()
    if courseid not in courses:
        raise CourseNotFoundException("Marketplace course not found")
    return courses[courseid]