def _check_container_with_txt_config_string( self, container, config_string=None ): """ Check whether the given container with TXT (INI-like) configuration is well-formed. :param container: the container :type container: Container :param config_string: the TXT (INI-like) configuration string :type config_string: string :rtype: :class:`aeneas.validator.ValidatorResult` """ self._log("Checking container with TXT config file") result = ValidatorResult() # if no config string was passed, try to read it from container if config_string is None: self._log("Trying to read config file from container") config_in_container = True config_contents = container.read_entry(container.entry_config_txt) if config_contents is None: msg = "Unable to read the contents of TXT config file." result.passed = False result.add_error(msg) self._log(msg) return result self._log("Config file found in container") else: self._log("Config string passed as parameter") config_contents = config_string config_in_container = False # check the txt config contents or string result = self.check_contents_txt_config_file( config_contents, config_in_container ) if not result.passed: self._log("Failed") return result # analyze the container self._log("Analyze the contents of the container") analyzer = AnalyzeContainer(container) if config_in_container: job = analyzer.analyze() else: job = analyzer.analyze_from_wizard(config_string) self._check_analyzed_job(job, container, result) # return result self._log(["Checking container with TXT config file: returning %s", result.passed]) return result
def _check_container_with_txt_config_string(self, container, config_string=None): """ Check whether the given container with TXT (INI-like) configuration is well-formed. :param container: the container :type container: Container :param config_string: the TXT (INI-like) configuration string :type config_string: string :rtype: :class:`aeneas.validator.ValidatorResult` """ self._log("Checking container with TXT config file") result = ValidatorResult() # if no config string was passed, try to read it from container if config_string is None: self._log("Trying to read config file from container") config_in_container = True config_contents = container.read_entry(container.entry_config_txt) if config_contents is None: msg = "Unable to read the contents of TXT config file." result.passed = False result.add_error(msg) self._log(msg) return result self._log("Config file found in container") else: self._log("Config string passed as parameter") config_contents = config_string config_in_container = False # check the txt config contents or string result = self.check_contents_txt_config_file(config_contents, config_in_container) if not result.passed: self._log("Failed") return result # analyze the container self._log("Analyze the contents of the container") analyzer = AnalyzeContainer(container) if config_in_container: job = analyzer.analyze() else: job = analyzer.analyze_from_wizard(config_string) self._check_analyzed_job(job, container, result) # return result self._log([ "Checking container with TXT config file: returning %s", result.passed ]) return result
def load_job_from_container(self, container_path, config_string=None): """ Validate the given container, and, if it is well formed, load the job from it. If ``config_string`` is ``None``, the container must contain a configuration file; otherwise use the provided config string (i.e., the wizard case). Return ``True`` if the job has been loaded successfully, ``False`` otherwise. :param container_path: the path to the input container :type container_path: string (path) :param config_string: the configuration string (from wizard) :type config_string: string :rtype: bool """ self._log("Loading job from container...") # validate container self._log("Validating container...") validator = Validator(logger=self.logger) if config_string == None: validator_result = validator.check_container(container_path) else: validator_result = validator.check_container_from_wizard( container_path, config_string ) if not validator_result.passed: self._log("Validating container: failed") self._log("Loading job from container: failed") return False self._log("Validating container: succeeded") try: # create working directory where the input container # will be decompressed self.working_directory = tempfile.mkdtemp(dir=gf.custom_tmp_dir()) self._log("Created working directory '%s'" % self.working_directory) # decompress self._log("Decompressing input container...") input_container = Container(container_path, logger=self.logger) input_container.decompress(self.working_directory) self._log("Decompressing input container... done") # create job from the working directory self._log("Creating job from working directory...") working_container = Container( self.working_directory, logger=self.logger ) analyzer = AnalyzeContainer(working_container, logger=self.logger) if config_string == None: self.job = analyzer.analyze() else: self.job = analyzer.analyze_from_wizard(config_string) self._log("Creating job from working directory... done") # set absolute path for text file and audio file # for each task in the job self._log("Setting absolute paths for tasks...") for task in self.job.tasks: task.text_file_path_absolute = gf.norm_join( self.working_directory, task.text_file_path ) task.audio_file_path_absolute = gf.norm_join( self.working_directory, task.audio_file_path ) self._log("Setting absolute paths for tasks... done") # return self._log("Loading job from container: succeeded") return True except: # failure: clean and return self.clean() self._log("Loading job from container: failed") return False
def load_job_from_container(self, container_path, config_string=None): """ Validate the given container, and, if it is well formed, load the job from it. If ``config_string`` is ``None``, the container must contain a configuration file; otherwise use the provided config string (i.e., the wizard case). Return ``True`` if the job has been loaded successfully, ``False`` otherwise. :param container_path: the path to the input container :type container_path: string (path) :param config_string: the configuration string (from wizard) :type config_string: string :rtype: bool """ self._log("Loading job from container...") # validate container self._log("Validating container...") validator = Validator(logger=self.logger) if config_string is None: validator_result = validator.check_container(container_path) else: validator_result = validator.check_container_from_wizard( container_path, config_string) if not validator_result.passed: self._log("Validating container: failed") self._log("Loading job from container: failed") return False self._log("Validating container: succeeded") try: # create working directory where the input container # will be decompressed self.working_directory = tempfile.mkdtemp(dir=gf.custom_tmp_dir()) self._log( ["Created working directory '%s'", self.working_directory]) # decompress self._log("Decompressing input container...") input_container = Container(container_path, logger=self.logger) input_container.decompress(self.working_directory) self._log("Decompressing input container... done") # create job from the working directory self._log("Creating job from working directory...") working_container = Container(self.working_directory, logger=self.logger) analyzer = AnalyzeContainer(working_container, logger=self.logger) if config_string is None: self.job = analyzer.analyze() else: self.job = analyzer.analyze_from_wizard(config_string) self._log("Creating job from working directory... done") # set absolute path for text file and audio file # for each task in the job self._log("Setting absolute paths for tasks...") for task in self.job.tasks: task.text_file_path_absolute = gf.norm_join( self.working_directory, task.text_file_path) task.audio_file_path_absolute = gf.norm_join( self.working_directory, task.audio_file_path) self._log("Setting absolute paths for tasks... done") # return self._log("Loading job from container: succeeded") return True except: # failure: clean and return self.clean() self._log("Loading job from container: failed") return False