Exemple #1
0
    def __init__(self, course_info, parent, settings):
        """
        Constructor method, initializes base CanvasEntity 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 = helpers.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
        CanvasEntity.__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, page_info, parent):
        """
        Constructor method, initializes base CanvasEntity 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 = helpers.get_corrected_name(self.page_item_info[u"title"])
        page_path = parent.get_path() + page_name

        # Initialize base class
        CanvasEntity.__init__(self,
                              id_number=page_id,
                              name=page_name,
                              sync_path=page_path,
                              parent=parent,
                              folder=False,
                              identifier=u"page")
Exemple #3
0
    def __init__(self, settings, api):
        """
        Constructor method, initializes base CanvasEntity 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
        helpers.clear_console()

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

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

        # Initialize base class
        CanvasEntity.__init__(self,
                              id_number=-1,
                              name=u"",
                              sync_path=sync_path,
                              api=api,
                              settings=settings,
                              synchronizer=self,
                              identifier=u"synchronizer")
Exemple #4
0
    def __init__(self,
                 module_info,
                 module_position,
                 parent,
                 identifier=u"module"):
        """, i
        Constructor method, initializes base CanvasEntity 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 = helpers.get_corrected_name(self.module_info[u"name"])
        module_path = parent.get_path() + u"%s - %s" % (module_position,
                                                        module_name)

        # Initialize base class
        CanvasEntity.__init__(self,
                              id_number=module_id,
                              name=module_name,
                              sync_path=module_path,
                              parent=parent,
                              identifier=identifier)
Exemple #5
0
    def __init__(self, assignment_info, parent):
        """
        Constructor method, initializes base CanvasEntity 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 = helpers.get_corrected_name(assignment_info[u"name"])
        assignment_path = parent.get_path() + assignment_name

        # Initialize base class
        CanvasEntity.__init__(self,
                              id_number=assignment_id,
                              name=assignment_name,
                              sync_path=assignment_path,
                              parent=parent,
                              identifier=u"assignment")
    def __init__(self, url_info, parent):
        """
        Constructor method, initializes base CanvasEntity 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 = helpers.get_corrected_name(self.url_info[u"title"])
        url_path = parent.get_path() + url_name

        # Initialize base class
        CanvasEntity.__init__(self,
                              id_number=url_id,
                              name=url_name,
                              sync_path=url_path,
                              parent=parent,
                              folder=False,
                              identifier=u"external_url")
Exemple #7
0
    def __init__(self, assignments_info, parent):
        """
        Constructor method, initializes base CanvasEntity 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
        CanvasEntity.__init__(self,
                              id_number=assignments_folder_id,
                              name=assignments_folder_name,
                              sync_path=assignments_folder_path,
                              parent=parent,
                              identifier=u"assignment_folder")
Exemple #8
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 = helpers.get_corrected_name(self.folder_info[u"name"])
        # extend the parent path by adding folder name
        folder_path = parent.get_path() + folder_name

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

        self.black_list = black_list