예제 #1
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")
예제 #2
0
    def print_settings(self, first_time_setup=True, clear=True):
        """ Print the settings currently in memory. Clear the console first if specified by the 'clear' parameter """
        if clear:
            static_functions.clear_console()

        if first_time_setup:
            print(
                ANSI.format(
                    u"This is a first time setup.\nYou must specify at least the following settings"
                    u" in order to run CanvasSync:\n", u"announcer"))
        else:
            print(ANSI.format(u"-----------------------------", u"file"))
            print(ANSI.format(u"CanvasSync - Current settings", u"file"))
            print(ANSI.format(u"-----------------------------\n", u"file"))
            print(ANSI.format(u"Standard settings", u"announcer"))

        print(ANSI.BOLD + u"[*] Sync path:             \t" + ANSI.ENDC +
              ANSI.BLUE + self.sync_path + ANSI.ENDC)
        print(ANSI.BOLD + u"[*] Canvas domain:         \t" + ANSI.ENDC +
              ANSI.BLUE + self.domain + ANSI.ENDC)
        print(ANSI.BOLD + u"[*] Authentication token:  \t" + ANSI.ENDC +
              ANSI.BLUE + self.token + ANSI.ENDC)

        if len(self.courses_to_sync) != 0:
            if self.courses_to_sync[0] == u"Not set":
                d = u""
            else:
                d = u"1) "
            print(ANSI.BOLD + u"[*] Courses to be synced:  \t%s" % d +
                  ANSI.ENDC + ANSI.BLUE + self.courses_to_sync[0] + ANSI.ENDC)

            for index, course in enumerate(self.courses_to_sync[1:]):
                print(u" " * 27 + u"\t%s) " % (index + 2) + ANSI.BLUE +
                      course + ANSI.ENDC)
예제 #3
0
    def print_advanced_settings(self, clear=True):
        """
        Print the advanced settings currently in memory.
        Clear the console first if specified by the 'clear' parameter
        """
        if clear:
            static_functions.clear_console()

        print(ANSI.format(u"\nAdvanced settings", u"announcer"))

        module_settings_string = ANSI.BOLD + u"[*] Sync module items:        \t" + ANSI.ENDC

        count = 0
        for item in self.modules_settings:
            if self.modules_settings[item]:
                d = u" & " if count != 0 else u""
                module_settings_string += d + ANSI.BLUE + item + ANSI.ENDC
                count += 1

        if count == 0:
            module_settings_string += ANSI.RED + u"False" + ANSI.ENDC

        print(module_settings_string)
        print(ANSI.BOLD + u"[*] Sync assignments:         \t" + ANSI.ENDC +
              (ANSI.GREEN if self.sync_assignments else ANSI.RED) +
              str(self.sync_assignments) + ANSI.ENDC)
        print(ANSI.BOLD + u"[*] Download linked files:    \t" + ANSI.ENDC +
              (ANSI.GREEN if self.download_linked else ANSI.RED) +
              str(self.download_linked) + ANSI.ENDC)
        print(ANSI.BOLD + u"[*] Avoid item duplicates:    \t" + ANSI.ENDC +
              (ANSI.GREEN if self.avoid_duplicates else ANSI.RED) +
              str(self.avoid_duplicates) + ANSI.ENDC)
        print(ANSI.BOLD + u"[*] Use course nicknames:     \t" + ANSI.ENDC +
              (ANSI.GREEN if self.use_nicknames else ANSI.RED) +
              str(self.use_nicknames) + ANSI.ENDC)
예제 #4
0
    def show(self):
        """ Show the folder hierarchy by printing every level """

        static_functions.clear_console()
        print(u"\n")
        print(text_type(self))

        for course in self:
            course.show()
예제 #5
0
def show_main_screen(settings_file_exists):
    """
    Prompt the user for initial choice of action. Does not allow Synchronization before settings file has been set
    """

    choice = -1
    to_do = "quit"
    while choice not in (0, 1, 2, 3, 4):
        static_functions.clear_console()

        # Load version string
        import CanvasSync
        version = CanvasSync.__version__

        title = u"CanvasSync, "
        pretty_string = u"-" * (len(title) + len(version))

        print(
            ANSI.format(
                u"%s\n%s%s\n%s" %
                (pretty_string, title, version, pretty_string), u"file"))

        print(
            ANSI.format(
                u"Automatically synchronize modules, assignments & files located on a Canvas web server.",
                u"announcer"))
        print(ANSI.format(u"\nWhat would you like to do?", u"underline"))
        print(u"\n\t1) " + ANSI.format(u"Synchronize my Canvas", u"blue"))
        print(u"\t2) " + ANSI.format(u"Set new settings", u"white"))
        print(u"\t3) " + ANSI.format(u"Show current settings", u"white"))
        print(u"\t4) " + ANSI.format(u"Show help", u"white"))
        print(u"\n\t0) " + ANSI.format(u"Quit", u"yellow"))

        try:
            choice = int(input(u"\nChoose number: "))
            if choice < 0 or choice > 4:
                continue
        except ValueError:
            continue

        if choice == 1 and not settings_file_exists:
            to_do = u"set_settings"
        else:
            to_do = [
                u"quit", u"sync", u"set_settings", u"show_settings",
                u"show_help"
            ][choice]

    return to_do
예제 #6
0
    api = InstructureApi(settings)

    # Start Synchronizer with the current settings
    synchronizer = Synchronizer(settings=settings, api=api)
    synchronizer.sync()

    # If here, sync was completed, show prompt
    print(ANSI.format(u"\n\n[*] Sync complete", formatting=u"bold"))


# If main module
if __name__ == u"__main__":

    if os.name == u"nt":
        # Warn Windows users
        static_functions.clear_console()
        input(
            u"\n[OBS] You are running CanvasSync on a Windows operating system.\n"
            u"      The application is not developed for Windows machines and may be\n"
            u"      unstable. Some pretty output formatting and tab-autocompletion\n"
            u"      is not supported... :-(\n"
            u"\n    Anyway, hit enter to start.")

    try:
        run_canvas_sync()
    except KeyboardInterrupt:
        print(
            ANSI.format(u"\n\n[*] Synchronization interrupted",
                        formatting=u"red"))
        sys.exit()