Exemple #1
0
    def __init__(self, course_info, parent, settings):
        """
        Constructor method, initializes base Entity class and adds all children Module objects to the list of children

        course_info   : dict    | A dictionary of information on the Canvas course object
        parent        : object  | The parent object, the Synchronizer object
        """

        self.course_info = course_info

        course_id = self.course_info[u"id"]

        course_name = static_functions.get_corrected_name(
            self.course_info[u"course_code"].split(";")[-1])

        if settings.use_nicknames:
            course_name = self.course_info[u"name"]

        course_path = parent.get_path() + course_name

        self.to_be_synced = True if course_name in parent.settings.courses_to_sync else False

        # Initialize base class
        Entity.__init__(self,
                        id_number=course_id,
                        name=course_name,
                        sync_path=course_path,
                        parent=parent,
                        identifier=u"course",
                        folder=self.to_be_synced)
Exemple #2
0
    def __init__(self, settings, api):
        """
        Constructor method, initializes base Entity class and adds all children Course objects to the list of children

        settings : object | A Settings object, has top-level sync path attribute
        api      : object | An InstructureApi object
        """

        if not settings.is_loaded():
            settings.load_settings("")

        # Start sync by clearing the console window
        static_functions.clear_console()

        # Get the corrected top-level sync path
        sync_path = static_functions.get_corrected_path(settings.sync_path,
                                                        False,
                                                        folder=True)

        # A dictionary to store lists of Entity objects added to the hierarchy under a course ID number
        self.entities = {}

        # Initialize base class
        Entity.__init__(self,
                        id_number=-1,
                        name=u"",
                        sync_path=sync_path,
                        api=api,
                        settings=settings,
                        synchronizer=self,
                        identifier=u"synchronizer")
Exemple #3
0
    def __init__(self, file_info, parent, add_to_list_of_entities=True):
        """
        Constructor method, initializes base Entity class

        assignment_info : dict   | A dictionary of information on the Canvas file object
        parent          : object | The parent object, a Module, SubHeader, Folder or Assignment object
        """

        self.file_info = file_info

        self.locked = self.file_info["locked_for_user"]

        file_id = self.file_info[u"id"]
        file_name = static_functions.get_corrected_name(
            self.file_info[u"display_name"])
        file_path = parent.get_path() + file_name

        # Initialize base class
        Entity.__init__(self,
                        id_number=file_id,
                        name=file_name,
                        sync_path=file_path,
                        parent=parent,
                        folder=False,
                        identifier=u"file",
                        add_to_list_of_entities=add_to_list_of_entities)
Exemple #4
0
    def __init__(self, folder_info, parent, black_list=False):
        """
        Constructor method, initializes base Module class and adds all children Folder and/or Item objects to
        the list of children

        folder_info     : dict   | A dictionary of information on the Canvas Folder object
        parent          : object | The parent object, a Folder or Course object
        """

        self.folder_info = folder_info

        folder_id = self.folder_info[u"id"]
        folder_name = static_functions.get_corrected_name(
            self.folder_info[u"name"])
        folder_path = parent.get_path() + folder_name

        # Initialize base Module class
        Entity.__init__(self,
                        id_number=folder_id,
                        name=folder_name,
                        sync_path=folder_path,
                        parent=parent,
                        identifier=u"folder")

        self.black_list = black_list
Exemple #5
0
    def __init__(self,
                 module_info,
                 module_position,
                 parent,
                 identifier=u"module"):
        """, i
        Constructor method, initializes base Entity class and adds all children Folder and/or Item objects to the
        list of children

        module_info     : dict   | A dictionary of information on the Canvas module object
        module_position : int    | An integer representing the position of the module in the folder (1 for first folder)
        parent          : object | The parent object, a Course object
        """

        self.module_info = module_info

        module_id = self.module_info[u"id"]
        module_name = static_functions.get_corrected_name(
            self.module_info[u"name"])
        module_path = parent.get_path() + u"%s - %s" % (module_position,
                                                        module_name)

        # Initialize base class
        Entity.__init__(self,
                        id_number=module_id,
                        name=module_name,
                        sync_path=module_path,
                        parent=parent,
                        identifier=identifier)
Exemple #6
0
    def __init__(self, page_info, parent):
        """
        Constructor method, initializes base Entity class

        page_info : dict   | A dictionary of information on the Canvas page object
        parent    : object | The parent object, a Module or SubHeader object
        """

        # Sometimes the Page object is initialized with a json dict of information on the file like object representing
        # the HTML page instead of an object on the page itself. This file like object does not store the actual HTML
        # body, which will be downloaded in the self.download() method. The slightly messy code below makes the class
        # functional with either information supplied.
        self.page_item_info = page_info
        self.page_info = self.page_item_info if u"id" not in self.page_item_info else None

        page_id = self.page_item_info[
            u"id"] if not self.page_info else self.page_info[u"page_id"]
        page_name = static_functions.get_corrected_name(
            self.page_item_info[u"title"])
        page_path = parent.get_path() + page_name

        # Initialize base class
        Entity.__init__(self,
                        id_number=page_id,
                        name=page_name,
                        sync_path=page_path,
                        parent=parent,
                        folder=False,
                        identifier=u"page")
Exemple #7
0
    def __init__(self, download_url, parent):
        """
        Constructor method, initializes base Entity class

        download_url    : string | A URL pointing to a file somewhere on the web
        parent          : object | The parent object, an Assignment object
        """

        self.download_url = download_url
        self.valid_url = True

        # Get the potential file name from the URL
        # OBS: We do not correct the name in this class, as we need to use the length of the name to determine
        # if the link is valid.
        file_name = os.path.split(download_url)[-1]

        # File path
        file_path = parent.get_path() + file_name

        # No file extension or weirdly long filename will not be allowed
        # (this is not strictly necessary as the regex should only match OK URLs)
        if not os.path.splitext(file_name)[-1] or len(file_name) > 60:
            self.valid_url = False

        # Initialize base class
        Entity.__init__(self,
                        id_number=-1,
                        name=file_name,
                        sync_path=file_path,
                        parent=parent,
                        folder=False,
                        identifier=u"linked_file")
Exemple #8
0
    def __init__(self, assignment_info, parent):
        """
        Constructor method, initializes base Entity class

        assignment_info : dict   | A dictionary of information on the Canvas assignment object
        parent          : object | The parent object, an AssignmentsFolder object
        """

        self.assignment_info = assignment_info

        assignment_id = self.assignment_info[u"id"]
        assignment_name = static_functions.get_corrected_name(assignment_info[u"name"])
        assignment_path = parent.get_path() + assignment_name

        # Initialize base class
        Entity.__init__(self,
                        id_number=assignment_id,
                        name=assignment_name,
                        sync_path=assignment_path,
                        parent=parent,
                        identifier=u"assignment")
Exemple #9
0
    def __init__(self, url_info, parent):
        """
        Constructor method, initializes base Entity class and synchronizes the Item (downloads if not downloaded)

        url_info : dict   | A dictionary of information on the Canvas ExternalUrl object
        parent   : object | The parent object, a Module or SubFolder object
        """
        self.url_info = url_info

        url_id = self.url_info[u"id"]
        url_name = static_functions.get_corrected_name(self.url_info[u"title"])
        url_path = parent.get_path() + url_name

        # Initialize base class
        Entity.__init__(self,
                        id_number=url_id,
                        name=url_name,
                        sync_path=url_path,
                        parent=parent,
                        folder=False,
                        identifier=u"external_url")
Exemple #10
0
    def __init__(self, assignments_info, parent):
        """
        Constructor method, initializes base Entity class

        assignments_info : dict   | A list of dictionaries of information on all Canvas assignments object under a course
        parent           : object | The parent object, a Course object
        """

        self.assignments_info = assignments_info

        # Initialize entity with hardcoded ID and name, we always want the folder to be named "Assignments"
        assignments_folder_id = -1
        assignments_folder_name = u"Assignments"
        assignments_folder_path = parent.get_path() + assignments_folder_name

        # Initialize base class
        Entity.__init__(self,
                        id_number=assignments_folder_id,
                        name=assignments_folder_name,
                        sync_path=assignments_folder_path,
                        parent=parent,
                        identifier=u"assignment_folder")