def _select_courses_to_download(self, courses: [Course]): """ Asks the user for the courses that should be downloaded. @param courses: All available courses """ download_course_ids = self.config_helper.get_download_course_ids() dont_download_course_ids = self.config_helper.get_dont_download_course_ids( ) print('') Log.info( 'To avoid downloading all the Moodle courses you are enrolled in, you can select which ones you want' + ' to download here. ') print('') choices = [] defaults = [] for i, course in enumerate(courses): choices.append(('%5i\t%s' % (course.id, course.fullname))) if ResultsHandler._should_download_course( course.id, download_course_ids, dont_download_course_ids): defaults.append(i) Log.special('Which of the courses should be downloaded?') Log.info( '[You can select with the space bar and confirm your selection with the enter key]' ) print('') selected_courses = cutie.select_multiple(options=choices, ticked_indices=defaults) download_course_ids = [] for i, course in enumerate(courses): if i in selected_courses: download_course_ids.append(course.id) self.config_helper.set_property('download_course_ids', download_course_ids) self.config_helper.remove_property('dont_download_course_ids')
def _set_options_of_courses(self, courses: [Course]): """ Let the user set special options for every single course """ download_course_ids = self.config_helper.get_download_course_ids() dont_download_course_ids = self.config_helper.get_dont_download_course_ids( ) print('') Log.info( 'You can set special settings for every single course.\n' + ' You can set these options:\n' + '- A different name for the course\n' + '- If a directory structure should be created for the course' + ' [create_directory_structure (cfs)].') print('') while True: choices = [] choices_courses = [] options_of_courses = self.config_helper.get_options_of_courses() choices.append('None') for course in courses: if ResultsHandler._should_download_course( course.id, download_course_ids, dont_download_course_ids): current_course_settings = options_of_courses.get( str(course.id), None) # create default settings if current_course_settings is None: current_course_settings = { 'original_name': course.fullname, 'overwrite_name_with': None, 'create_directory_structure': True, } # create list of options overwrite_name_with = current_course_settings.get( 'overwrite_name_with', None) create_directory_structure = current_course_settings.get( 'create_directory_structure', True) if overwrite_name_with is not None and overwrite_name_with != course.fullname: choices.append( ('%5i\t%s (%s) cfs=%s' % (course.id, overwrite_name_with, course.fullname, create_directory_structure))) else: choices.append( ('%5i\t%s cfs=%s' % (course.id, course.fullname, create_directory_structure))) choices_courses.append(course) print('') Log.special( 'For which of the following course do you want to change the settings?' ) print('[Confirm your selection with the Enter key]') print('') selected_course = cutie.select(options=choices) if selected_course == 0: break else: self._change_settings_of(choices_courses[selected_course - 1], options_of_courses)