Пример #1
0
    def _update_cache(self, courseid):
        """
        Updates the cache
        :param courseid: the (valid) course id of the course
        :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
        """
        path_to_descriptor = self._get_course_descriptor_path(courseid)
        try:
            course_descriptor = loads_json_or_yaml(path_to_descriptor, self._filesystem.get(path_to_descriptor).decode("utf8"))
        except Exception as e:
            raise CourseUnreadableException(str(e))

        last_modif = {path_to_descriptor: self._filesystem.get_last_modification_time(path_to_descriptor)}
        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_modif["$i18n/" + lang + ".mo"] = translations_fs.get_last_modification_time(lang + ".mo")

        self._cache[courseid] = (
            self._course_class(courseid, course_descriptor, self.get_course_fs(courseid), self._task_factory, self._hook_manager),
            last_modif
        )

        self._task_factory.update_cache_for_course(courseid)
Пример #2
0
    def _update_cache(self, courseid):
        """
        Updates the cache
        :param courseid: the (valid) course id of the course
        :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
        """
        path_to_descriptor = self._get_course_descriptor_path(courseid)
        try:
            course_descriptor = loads_json_or_yaml(
                path_to_descriptor,
                self._filesystem.get(path_to_descriptor).decode("utf8"))
        except Exception as e:
            raise CourseUnreadableException(str(e))

        last_modif = {
            path_to_descriptor:
            self._filesystem.get_last_modification_time(path_to_descriptor)
        }
        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_modif[
                        "$i18n/" + lang +
                        ".mo"] = translations_fs.get_last_modification_time(
                            lang + ".mo")

        self._cache[courseid] = (self._course_class(
            courseid, course_descriptor, self.get_course_fs(courseid),
            self._task_factory, self._hook_manager), last_modif)

        self._task_factory.update_cache_for_course(courseid)
Пример #3
0
 def _get_git_template_list(self):
     """
     :return: the list of template linked to git
     """
     path = "gitTemplateList/list.yaml"
     return loads_json_or_yaml(path,
                               self._filesystem.get(path).decode("utf-8"))
def get_all_marketplace_courses():
    r = requests.get(MARKETPLACE_URL)
    marketplace_file = loads_json_or_yaml("marketplace.json", r.content)
    try:
        return {course["id"]: MarketplaceCourse(course) for course in marketplace_file}
    except:
        logging.getLogger("inginious.webapp.marketplace").info("Could not load marketplace")
        return {}
Пример #5
0
 def get_course_descriptor_content(self, courseid):
     """
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
     :return: the content of the dict that describes the course
     """
     path = self._get_course_descriptor_path(courseid)
     return loads_json_or_yaml(path, self._filesystem.get(path).decode("utf-8"))
Пример #6
0
 def get_course_descriptor_content(self, courseid):
     """
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
     :return: the content of the dict that describes the course
     """
     path = self._get_course_descriptor_path(courseid)
     return loads_json_or_yaml(path,
                               self._filesystem.get(path).decode("utf-8"))
Пример #7
0
def get_toc(course):
    """
    :param course: the course containing the toc
    :return: the content of the file toc.yaml if the file exist [] otherwise
    """
    course_fs = course.get_fs()
    if course_fs.exists("toc.yaml"):
        return loads_json_or_yaml("toc.yaml",
                                  course_fs.get("toc.yaml").decode("utf-8"))
    else:
        return []
Пример #8
0
 def _update_cache(self, courseid):
     """
     Updates the cache
     :param courseid: the (valid) course id of the course
     :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
     """
     path_to_descriptor = self._get_course_descriptor_path(courseid)
     try:
         course_descriptor = loads_json_or_yaml(
             path_to_descriptor,
             self._filesystem.get(path_to_descriptor).decode("utf8"))
         last_modification = self._filesystem.get_last_modification_time(
             path_to_descriptor)
     except Exception as e:
         raise CourseUnreadableException(str(e))
     self._cache[courseid] = (self._course_class(courseid,
                                                 course_descriptor,
                                                 self._task_factory,
                                                 self._hook_manager),
                              last_modification)
     self._task_factory.update_cache_for_course(courseid)