def _replace_faces(self, widget): self.logger.info("Start Replace Faces") # get values from UI elements rtf = self.profile_manager.prf_cfg['rtf'] img_dir = self.profile_manager.prf_cfg['img_dir'] profile = self.profile_manager.cur_prf mode = self.genmde_lst.value if not os.path.isfile(rtf): self._throw_error("The RTF file doesn't exist!") self.gen_prg.stop() self.profile_manager.prf_cfg['rtf'] = '' return if not os.path.isdir(img_dir): self._throw_error("The image directory doesn't exist!") self.gen_prg.stop() self.profile_manager.prf_cfg['img_dir'] = '' return # Check if valid image_directory contains all the needed subfolders img_dirs = set() for entry in os.scandir(img_dir): if entry.is_dir(): img_dirs.add(entry.name) for fp_dir in self.facepack_dirs: if fp_dir not in img_dirs: self._throw_error( "Folder {} is missing in the image directory".format( fp_dir)) self.gen_prg.stop() return self.logger.info("rtf: {}".format(rtf)) self.logger.info("img_dir: {}".format(img_dir)) self.logger.info("profile: {}".format(profile)) self.logger.info("mode: {}".format(mode)) self.set_btns(False) self.gen_prg.start() self.gen_prg.update_label("Parsing RTF") # yield 0.1 rtf_parser = RTF_Parser() if not rtf_parser.is_rtf_valid(rtf): self._throw_error("The RTF file is invalid!") self.gen_prg.stop() return rtf_data = rtf_parser.parse_rtf(rtf) self.gen_prg.update_progress(20) self.gen_prg.update_label("Map player to ethnicity") # yield 0.1 mapping_data = Mapper(img_dir, self.profile_manager).generate_mapping( rtf_data, mode, self.gendup.is_on) self.gen_prg.update_progress(60) self.gen_prg.update_label("Generate config.xml") # yield 0.1 self.profile_manager.write_xml(mapping_data) # save profile metadata (used pics and config.xml) self.gen_prg.update_label("Save metadata for profile") self.gen_prg.update_progress(10) # yield 0.1 Config_Manager().save_config( str(self.paths.app) + "/.user/" + profile + ".json", self.profile_manager.prf_cfg) self.gen_prg.update_progress(10) # yield 0.1 self.gen_prg.update_label("Finished! :)") # yield 0.1 self._show_info("Finished! :)") self.gen_prg.stop() self.set_btns(True)
def test_valid_rtf(self): self.assertTrue(RTF_Parser.is_rtf_valid(None, "newganmanager/test/test_simple_UID.rtf")) self.assertFalse(RTF_Parser.is_rtf_valid(None, "newganmanager/test/false.rtf"))