當前位置: 首頁>>代碼示例>>Python>>正文


Python Validator.check_container_from_wizard方法代碼示例

本文整理匯總了Python中aeneas.validator.Validator.check_container_from_wizard方法的典型用法代碼示例。如果您正苦於以下問題:Python Validator.check_container_from_wizard方法的具體用法?Python Validator.check_container_from_wizard怎麽用?Python Validator.check_container_from_wizard使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aeneas.validator.Validator的用法示例。


在下文中一共展示了Validator.check_container_from_wizard方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container_from_wizard [as 別名]
def main():
    """ Entry point """
    if len(sys.argv) < 3:
        usage()
        return
    validator = Validator()
    mode = sys.argv[1]
    result = None
    msg = ""

    if mode == "config":
        if sys.argv[2].endswith(".txt"):
            try:
                config_file = open(sys.argv[2], "r")
                config_contents = config_file.read()
                config_file.close()
                result = validator.check_contents_txt_config_file(config_contents, True)
                msg = "TXT configuration"
            except:
                print "[ERRO] Unable to read file %s" % sys.argv[2]
        elif sys.argv[2].endswith(".xml"):
            try:
                config_file = open(sys.argv[2], "r")
                config_contents = config_file.read()
                config_file.close()
                result = validator.check_contents_xml_config_file(config_contents)
                msg = "XML configuration"
            except:
                print "[ERRO] Unable to read file %s" % sys.argv[2]
        else:
            usage()
            return
    elif mode == "container":
        result = validator.check_container(sys.argv[2])
        msg = "container"
    elif mode == "job":
        result = validator.check_job_configuration(sys.argv[2])
        msg = "job configuration string"
    elif mode == "task":
        result = validator.check_task_configuration(sys.argv[2])
        msg = "task configuration string"
    elif mode == "wizard":
        if len(sys.argv) < 4:
            usage()
            return
        result = validator.check_container_from_wizard(sys.argv[2], sys.argv[3])
        msg = "container + configuration string from wizard"
    else:
        usage()
        return

    if result.passed:
        print "[INFO] Valid %s" % msg
        if len(result.warnings) > 0:
            for warning in result.warnings:
                print "[WARN] " + warning
    else:
        print "[INFO] Invalid %s" % msg
        for error in result.errors:
            print "[ERRO] " + error
開發者ID:fduch2k,項目名稱:aeneas,代碼行數:62,代碼來源:validate.py

示例2: load_job_from_container

# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container_from_wizard [as 別名]
    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
開發者ID:dburt,項目名稱:aeneas,代碼行數:86,代碼來源:executejob.py


注:本文中的aeneas.validator.Validator.check_container_from_wizard方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。