def load(self, exercise, dom, path): #Name exercise.set_name(None) #Language languageManager = LanguagesManager() exercise.set_language_id(languageManager.get_default_language().id) #Template exercise.set_template(False) #Random order exercise.set_random_order(False) xml_progress = dom.getElementsByTagName("progress")[0] currentSequence = int(get_text(xml_progress.getElementsByTagName("current_sequence")[0].childNodes)) currentWord = int(get_text(xml_progress.getElementsByTagName("current_word")[0].childNodes)) xml_sequences = xml_progress.getElementsByTagName("sequences")[0] progress = [] for xml_sequence in xml_sequences.getElementsByTagName("sequence"): id = int(get_text(xml_sequence.getElementsByTagName("id")[0].childNodes)) state = get_text(xml_sequence.getElementsByTagName("state")[0].childNodes) words = [] repeat_count = 0 if state == "in_progress": xml_words = xml_sequence.getElementsByTagName("words")[0] for xml_world in xml_words.getElementsByTagName("word"): words.append(get_text(xml_world.childNodes)) progress.append((id, state, words, repeat_count)) # Stats xml_stats = dom.getElementsByTagName("stats")[0] exercise.set_repeat_count(int(get_text(xml_stats.getElementsByTagName("repeat_count")[0].childNodes))) #Subexercises subExos = [] subExercise = SubExercise(exercise) #Sequences progress = [] xml_progress = dom.getElementsByTagName("progress")[0] xml_sequences = xml_progress.getElementsByTagName("sequences")[0] for xml_sequence in xml_sequences.getElementsByTagName("sequence"): id = int(get_text(xml_sequence.getElementsByTagName("id")[0].childNodes)) state = get_text(xml_sequence.getElementsByTagName("state")[0].childNodes) words = [] if state == "in_progress": xml_words = xml_sequence.getElementsByTagName("words")[0] for xml_world in xml_words.getElementsByTagName("word"): words.append(get_text(xml_world.childNodes)) progress.append((id, state, words)) #Paths xml_paths = dom.getElementsByTagName("paths")[0] subExercise.set_video_path(get_text(xml_paths.getElementsByTagName("video")[0].childNodes)) subExercise.set_exercise_path(get_text(xml_paths.getElementsByTagName("exercice")[0].childNodes)) subExercise.set_translation_path(get_text(xml_paths.getElementsByTagName("translation")[0].childNodes)) exercise.subExercisesList.append(subExercise) subExos.append(progress) #Convert relative path for subExo in exercise.subExercisesList: if not os.path.isfile(subExo.get_exercise_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_exercise_path()) if not os.path.isfile(absPath): subExo.set_exercise_path("") else: subExo.set_exercise_path(absPath) if not os.path.isfile(subExo.get_video_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_video_path()) if not os.path.isfile(absPath): subExo.set_video_path("") else: subExo.set_video_path(absPath) if not os.path.isfile(subExo.get_translation_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_translation_path()) if not os.path.isfile(absPath): subExo.set_translation_path("") else: subExo.set_translation_path(absPath) exercise.initialize() self.update_sequence_list() exercise.goto_sequence(currentSequence) exercise.get_current_sequence().set_active_word_index(currentWord) if not exercise.is_template(): exercise.set_output_save_path(path) return exercise
def load(exercise, dom, path): #Name if len(dom.getElementsByTagName("name")) > 0: exercise.set_name( get_text(dom.getElementsByTagName("name")[0].childNodes)) #Language if len(dom.getElementsByTagName("language")) > 0: exercise.set_language_id( get_text(dom.getElementsByTagName("language")[0].childNodes)) else: languageManager = LanguagesManager() exercise.set_language_id(languageManager.get_default_language().id) #Template if len(dom.getElementsByTagName("template")) > 0: exercise.set_template( get_text(dom.getElementsByTagName("template")[0].childNodes) == "True") #Random order if len(dom.getElementsByTagName("random_order")) > 0: exercise.set_random_order( get_text(dom.getElementsByTagName("random_order")[0].childNodes) == "True") #Locks if len(dom.getElementsByTagName("locks")) > 0: xml_locks = dom.getElementsByTagName("locks")[0] #Correction lock if len(xml_locks.getElementsByTagName("correction_lock")) > 0: exercise.lock_correction = True xml_lock = xml_locks.getElementsByTagName("correction_lock")[0] if len(xml_lock.getElementsByTagName("hash")) > 0: exercise.lock_correction_password = get_text( xml_lock.getElementsByTagName("hash")[0].childNodes) if len(xml_lock.getElementsByTagName("salt")) > 0: exercise.lock_correction_salt = get_text( xml_lock.getElementsByTagName("salt")[0].childNodes) #Properties lock if len(xml_locks.getElementsByTagName("properties_lock")) > 0: exercise.lock_properties = True xml_lock = xml_locks.getElementsByTagName("properties_lock")[0] if len(xml_lock.getElementsByTagName("hash")) > 0: exercise.lock_properties_password = get_text( xml_lock.getElementsByTagName("hash")[0].childNodes) if len(xml_lock.getElementsByTagName("salt")) > 0: exercise.lock_properties_salt = get_text( xml_lock.getElementsByTagName("salt")[0].childNodes) #Help lock if len(xml_locks.getElementsByTagName("help_lock")) > 0: exercise.lock_help = True #Exercise xml_exercise = dom.getElementsByTagName("exercise")[0] #Exercise - CurrentWord currentWord = int( get_text( xml_exercise.getElementsByTagName("current_word")[0].childNodes)) #Exercise - CurrentSequence currentSequence = int( get_text( xml_exercise.getElementsByTagName("current_sequence") [0].childNodes)) # Stats xml_stats = dom.getElementsByTagName("stats")[0] exercise.set_repeat_count( int( get_text( xml_stats.getElementsByTagName("repeat_count")[0].childNodes))) # Properties if len(dom.getElementsByTagName("properties")) > 0: xml_properties = dom.getElementsByTagName("properties")[0] if len(xml_properties.getElementsByTagName( "repeat_after_complete")) > 0: exercise.set_repeat_after_completed( get_text( xml_properties.getElementsByTagName( "repeat_after_complete")[0].childNodes) == "True") if len(xml_properties.getElementsByTagName( "time_between_sequence")) > 0: exercise.set_time_between_sequence( float( get_text( xml_properties.getElementsByTagName( "time_between_sequence")[0].childNodes))) if len(xml_properties.getElementsByTagName("max_sequence_length")) > 0: exercise.set_max_sequence_length( float( get_text( xml_properties.getElementsByTagName( "max_sequence_length")[0].childNodes))) if len(xml_properties.getElementsByTagName("play_margin_before")) > 0: exercise.set_play_margin_before( int( get_text( xml_properties.getElementsByTagName( "play_margin_before")[0].childNodes))) if len(xml_properties.getElementsByTagName("play_margin_after")) > 0: exercise.set_play_margin_after( int( get_text( xml_properties.getElementsByTagName( "play_margin_after")[0].childNodes))) if len(xml_properties.getElementsByTagName( "use_dynamic_correction")) > 0: exercise.set_use_dynamic_correction( get_text( xml_properties.getElementsByTagName( "use_dynamic_correction")[0].childNodes) == "True") if len( xml_properties.getElementsByTagName( "repeat_count_by_sequence_limit")) > 0: exercise.set_repeat_count_limit_by_sequence( int( get_text( xml_properties.getElementsByTagName( "repeat_count_by_sequence_limit")[0].childNodes))) #Subexercises subExos = [] for xml_subExercise in xml_exercise.getElementsByTagName("sub_exercise"): subExercise = SubExercise(exercise) #Sequences xml_sequences = xml_subExercise.getElementsByTagName("sequences")[0] progress = [] for xml_sequence in xml_sequences.getElementsByTagName("sequence"): id = int( get_text( xml_sequence.getElementsByTagName("id")[0].childNodes)) state = get_text( xml_sequence.getElementsByTagName("state")[0].childNodes) #Sequence repeat count if len(xml_sequence.getElementsByTagName("repeat_count")) > 0: repeat_count = int( get_text( xml_sequence.getElementsByTagName("repeat_count") [0].childNodes)) else: repeat_count = 0 words = [] if state == "in_progress": xml_words = xml_sequence.getElementsByTagName("words")[0] for xml_world in xml_words.getElementsByTagName("word"): words.append(get_text(xml_world.childNodes)) progress.append((id, state, words, repeat_count)) #Paths xml_paths = xml_subExercise.getElementsByTagName("paths")[0] subExercise.set_video_path( get_text(xml_paths.getElementsByTagName("video")[0].childNodes)) subExercise.set_exercise_path( get_text(xml_paths.getElementsByTagName("exercise")[0].childNodes)) subExercise.set_translation_path( get_text( xml_paths.getElementsByTagName("translation")[0].childNodes)) exercise.subExercisesList.append(subExercise) subExos.append(progress) #Convert relative path for subExo in exercise.subExercisesList: if not os.path.isfile(subExo.get_exercise_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_exercise_path()) if not os.path.isfile(absPath): subExo.set_exercise_path("") else: subExo.set_exercise_path(absPath) if not os.path.isfile(subExo.get_video_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_video_path()) if not os.path.isfile(absPath): subExo.set_video_path("") else: subExo.set_video_path(absPath) if not os.path.isfile(subExo.get_translation_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_translation_path()) if not os.path.isfile(absPath): subExo.set_translation_path("") else: subExo.set_translation_path(absPath) exercise.initialize() update_sequence_list(exercise, subExos) exercise.goto_sequence(currentSequence) exercise.get_current_sequence().set_active_word_index(currentWord) if not exercise.is_template(): exercise.set_output_save_path(path) return exercise
def load(exercise, dom, path): #Name if len(dom.getElementsByTagName("name")) > 0: exercise.set_name(get_text(dom.getElementsByTagName("name")[0].childNodes)) #Language if len(dom.getElementsByTagName("language")) > 0: exercise.set_language_id(get_text(dom.getElementsByTagName("language")[0].childNodes)) else: languageManager = LanguagesManager() exercise.set_language_id(languageManager.get_default_language().id) #Template if len(dom.getElementsByTagName("template")) > 0: exercise.set_template(get_text(dom.getElementsByTagName("template")[0].childNodes) == "True") #Random order if len(dom.getElementsByTagName("random_order")) > 0: exercise.set_random_order(get_text(dom.getElementsByTagName("random_order")[0].childNodes) == "True") #Locks if len(dom.getElementsByTagName("locks")) > 0: xml_locks = dom.getElementsByTagName("locks")[0] #Correction lock if len(xml_locks.getElementsByTagName("correction_lock")) > 0: exercise.lock_correction = True xml_lock = xml_locks.getElementsByTagName("correction_lock")[0] if len(xml_lock.getElementsByTagName("hash")) > 0: exercise.lock_correction_password = get_text(xml_lock.getElementsByTagName("hash")[0].childNodes) if len(xml_lock.getElementsByTagName("salt")) > 0: exercise.lock_correction_salt = get_text(xml_lock.getElementsByTagName("salt")[0].childNodes) #Properties lock if len(xml_locks.getElementsByTagName("properties_lock")) > 0: exercise.lock_properties = True xml_lock = xml_locks.getElementsByTagName("properties_lock")[0] if len(xml_lock.getElementsByTagName("hash")) > 0: exercise.lock_properties_password = get_text(xml_lock.getElementsByTagName("hash")[0].childNodes) if len(xml_lock.getElementsByTagName("salt")) > 0: exercise.lock_properties_salt = get_text(xml_lock.getElementsByTagName("salt")[0].childNodes) #Help lock if len(xml_locks.getElementsByTagName("help_lock")) > 0: exercise.lock_help = True #Exercise xml_exercise = dom.getElementsByTagName("exercise")[0] #Exercise - CurrentWord currentWord = int(get_text(xml_exercise.getElementsByTagName("current_word")[0].childNodes)) #Exercise - CurrentSequence currentSequence = int(get_text(xml_exercise.getElementsByTagName("current_sequence")[0].childNodes)) # Stats xml_stats = dom.getElementsByTagName("stats")[0] exercise.set_repeat_count(int(get_text(xml_stats.getElementsByTagName("repeat_count")[0].childNodes))) # Properties if len(dom.getElementsByTagName("properties")) > 0: xml_properties = dom.getElementsByTagName("properties")[0] if len(xml_properties.getElementsByTagName("repeat_after_complete")) > 0: exercise.set_repeat_after_completed(get_text(xml_properties.getElementsByTagName("repeat_after_complete")[0].childNodes) == "True") if len(xml_properties.getElementsByTagName("time_between_sequence")) > 0: exercise.set_time_between_sequence(float(get_text(xml_properties.getElementsByTagName("time_between_sequence")[0].childNodes))) if len(xml_properties.getElementsByTagName("max_sequence_length")) > 0: exercise.set_max_sequence_length(float(get_text(xml_properties.getElementsByTagName("max_sequence_length")[0].childNodes))) if len(xml_properties.getElementsByTagName("play_margin_before")) > 0: exercise.set_play_margin_before(int(get_text(xml_properties.getElementsByTagName("play_margin_before")[0].childNodes))) if len(xml_properties.getElementsByTagName("play_margin_after")) > 0: exercise.set_play_margin_after(int(get_text(xml_properties.getElementsByTagName("play_margin_after")[0].childNodes))) if len(xml_properties.getElementsByTagName("use_dynamic_correction")) > 0: exercise.set_use_dynamic_correction(get_text(xml_properties.getElementsByTagName("use_dynamic_correction")[0].childNodes) == "True") if len(xml_properties.getElementsByTagName("repeat_count_by_sequence_limit")) > 0: exercise.set_repeat_count_limit_by_sequence(int(get_text(xml_properties.getElementsByTagName("repeat_count_by_sequence_limit")[0].childNodes))) #Subexercises subExos = [] for xml_subExercise in xml_exercise.getElementsByTagName("sub_exercise"): subExercise = SubExercise(exercise) #Sequences xml_sequences = xml_subExercise.getElementsByTagName("sequences")[0] progress = [] for xml_sequence in xml_sequences.getElementsByTagName("sequence"): id = int(get_text(xml_sequence.getElementsByTagName("id")[0].childNodes)) state = get_text(xml_sequence.getElementsByTagName("state")[0].childNodes) #Sequence repeat count if len(xml_sequence.getElementsByTagName("repeat_count")) > 0: repeat_count = int(get_text(xml_sequence.getElementsByTagName("repeat_count")[0].childNodes)) else: repeat_count = 0 words = [] if state == "in_progress": xml_words = xml_sequence.getElementsByTagName("words")[0] for xml_world in xml_words.getElementsByTagName("word"): words.append(get_text(xml_world.childNodes)) progress.append((id, state, words, repeat_count)) #Paths xml_paths = xml_subExercise.getElementsByTagName("paths")[0] subExercise.set_video_path(get_text(xml_paths.getElementsByTagName("video")[0].childNodes)) subExercise.set_exercise_path(get_text(xml_paths.getElementsByTagName("exercise")[0].childNodes)) subExercise.set_translation_path(get_text(xml_paths.getElementsByTagName("translation")[0].childNodes)) exercise.subExercisesList.append(subExercise) subExos.append(progress) #Convert relative path for subExo in exercise.subExercisesList: if not os.path.isfile(subExo.get_exercise_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_exercise_path()) if not os.path.isfile(absPath): subExo.set_exercise_path("") else: subExo.set_exercise_path(absPath) if not os.path.isfile(subExo.get_video_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_video_path()) if not os.path.isfile(absPath): subExo.set_video_path("") else: subExo.set_video_path(absPath) if not os.path.isfile(subExo.get_translation_path()): absPath = os.path.join(os.path.dirname(path), subExo.get_translation_path()) if not os.path.isfile(absPath): subExo.set_translation_path("") else: subExo.set_translation_path(absPath) exercise.initialize() update_sequence_list(exercise, subExos) exercise.goto_sequence(currentSequence) exercise.get_current_sequence().set_active_word_index(currentWord) if not exercise.is_template(): exercise.set_output_save_path(path) return exercise