<commit_before>from path import path
from xmodule.modulestore import Location
from xmodule.seq_module import SequenceDescriptor, SequenceModule

class CourseDescriptor(SequenceDescriptor):
    module_class = SequenceModule

    @classmethod
    def id_to_location(cls, course_id):
        org, course, name = course_id.split('/')
        return Location('i4x', org, course, 'course', name)

    @property
    def id(self):
        return "/".join([self.location.org, self.location.course, self.location.name])

    @property
    def title(self):
        self.metadata['display_name']

    @property
    def instructors(self):
        return self.get_about_section("instructors").split("\n")

    def get_about_section(self, section_key):
        """
        This returns the snippet of html to be rendered on the course about page, given the key for the section.
        Valid keys:
        - title
        - university
        - number
        - short_description
        - description
        - key_dates (includes start, end, exams, etc)
        - video
        - course_staff_short
        - course_staff_extended
        - requirements
        - syllabus
        - textbook
        - faq
        - more_info
        """

        # Many of these are stored as html files instead of some semantic markup. This can change without effecting
        # this interface when we find a good format for defining so many snippets of text/html.

        # TODO: Remove number, instructors from this list
        if section_key in ['short_description', 'description', 'key_dates', 'video', 'course_staff_short', 'course_staff_extended',
                            'requirements', 'syllabus', 'textbook', 'faq', 'more_info', 'number', 'instructors']:
            try:
                with self.system.resources_fs.open(path("about") / section_key + ".html") as htmlFile:
                    return htmlFile.read()
            except IOError:
                return "! About section missing !"
        elif section_key == "title":
            return self.name
        elif section_key == "university":
            return self.location.org
        elif section_key == "number":
            return self.number

        raise KeyError("Invalid about key " + str(section_key))

    def get_info_section(self, section_key):
        """
        This returns the snippet of html to be rendered on the course info page, given the key for the section.
        Valid keys:
        - handouts
        - guest_handouts
        - updates
        - guest_updates
        """

        # Many of these are stored as html files instead of some semantic markup. This can change without effecting
        # this interface when we find a good format for defining so many snippets of text/html.

        if section_key in ['handouts', 'guest_handouts', 'updates', 'guest_updates']:
            try:
                with self.system.resources_fs.open(path("info") / section_key + ".html") as htmlFile:
                    return htmlFile.read()
            except IOError:
                return "! About section missing !"

        raise KeyError("Invalid about key " + str(section_key))<commit_msg>Fixed exception type when about or info section missing.<commit_after>from fs.errors import ResourceNotFoundError
from path import path

from xmodule.modulestore import Location
from xmodule.seq_module import SequenceDescriptor, SequenceModule


class CourseDescriptor(SequenceDescriptor):
    module_class = SequenceModule

    @classmethod
    def id_to_location(cls, course_id):
        org, course, name = course_id.split('/')
        return Location('i4x', org, course, 'course', name)

    @property
    def id(self):
        return "/".join([self.location.org, self.location.course, self.location.name])

    @property
    def title(self):
        self.metadata['display_name']

    @property
    def instructors(self):
        return self.get_about_section("instructors").split("\n")

    def get_about_section(self, section_key):
        """
        This returns the snippet of html to be rendered on the course about page, given the key for the section.
        Valid keys:
        - title
        - university
        - number
        - short_description
        - description
        - key_dates (includes start, end, exams, etc)
        - video
        - course_staff_short
        - course_staff_extended
        - requirements
        - syllabus
        - textbook
        - faq
        - more_info
        """

        # Many of these are stored as html files instead of some semantic markup. This can change without effecting
        # this interface when we find a good format for defining so many snippets of text/html.

        # TODO: Remove number, instructors from this list
        if section_key in ['short_description', 'description', 'key_dates', 'video', 'course_staff_short', 'course_staff_extended',
                            'requirements', 'syllabus', 'textbook', 'faq', 'more_info', 'number', 'instructors']:
            try:
                with self.system.resources_fs.open(path("about") / section_key + ".html") as htmlFile:
                    return htmlFile.read()
            except ResourceNotFoundError:
                return "! About section missing !"
        elif section_key == "title":
            return self.name
        elif section_key == "university":
            return self.location.org
        elif section_key == "number":
            return self.number

        raise KeyError("Invalid about key " + str(section_key))

    def get_info_section(self, section_key):
        """
        This returns the snippet of html to be rendered on the course info page, given the key for the section.
        Valid keys:
        - handouts
        - guest_handouts
        - updates
        - guest_updates
        """

        # Many of these are stored as html files instead of some semantic markup. This can change without effecting
        # this interface when we find a good format for defining so many snippets of text/html.

        if section_key in ['handouts', 'guest_handouts', 'updates', 'guest_updates']:
            try:
                with self.system.resources_fs.open(path("info") / section_key + ".html") as htmlFile:
                    return htmlFile.read()
            except ResourceNotFoundError:
                return "! Info section missing !"

        raise KeyError("Invalid about key " + str(section_key))
{'fraction_non_alphanumeric': 0.08583823985125504, 'fraction_numerical': 0.0003098853424233034, 'mean_word_length': 2.235588972431078, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2390819', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1622, 'n_words': 553}