本文整理匯總了Python中aeneas.validator.Validator.check_container方法的典型用法代碼示例。如果您正苦於以下問題:Python Validator.check_container方法的具體用法?Python Validator.check_container怎麽用?Python Validator.check_container使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aeneas.validator.Validator
的用法示例。
在下文中一共展示了Validator.check_container方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [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
示例2: test_check_container_xml_07
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [as 別名]
def test_check_container_xml_07(self):
logger = Logger()
validator = Validator(logger=logger)
container_path = get_abs_path("res/validator/job_xml_config_not_root_nested")
result = validator.check_container(container_path)
self.assertTrue(result.passed)
self.assertEqual(len(result.errors), 0)
示例3: test_check_container_xml_05
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [as 別名]
def test_check_container_xml_05(self):
logger = Logger()
validator = Validator(logger=logger)
container_path = get_abs_path("res/validator/job_xml_config_bad_4")
result = validator.check_container(container_path)
self.assertFalse(result.passed)
self.assertGreater(len(result.errors), 0)
示例4: container
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [as 別名]
def container(self, path, expected):
validator = Validator()
result = validator.check_container(gf.absolute_path(path, __file__))
self.assertEqual(result.passed, expected)
if expected:
self.assertEqual(len(result.errors), 0)
else:
self.assertGreater(len(result.errors), 0)
示例5: perform_command
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [as 別名]
def perform_command(self):
"""
Perform command and return the appropriate exit code.
:rtype: int
"""
if len(self.actual_arguments) < 2:
return self.print_help()
mode = self.actual_arguments[0]
validator = Validator(rconf=self.rconf, logger=self.logger)
if mode == u"config":
config_file_path = self.actual_arguments[1]
config_txt = None
if config_file_path.lower().endswith(u".txt"):
config_txt = True
elif config_file_path.lower().endswith(u".xml"):
config_txt = False
else:
return self.print_help()
if not self.check_input_file(config_file_path):
return self.ERROR_EXIT_CODE
contents = gf.read_file_bytes(config_file_path)
if contents is None:
return self.ERROR_EXIT_CODE
if config_txt:
result = validator.check_config_txt(contents)
msg = u"TXT configuration"
else:
result = validator.check_config_xml(contents)
msg = "XML configuration"
elif mode == u"container":
container_path = self.actual_arguments[1]
result = validator.check_container(container_path)
msg = "container"
elif mode == u"job":
config_string = self.actual_arguments[1]
result = validator.check_configuration_string(config_string, is_job=True)
msg = u"job configuration string"
elif mode == u"task":
config_string = self.actual_arguments[1]
result = validator.check_configuration_string(config_string, is_job=False, external_name=True)
msg = u"task configuration string"
elif mode == u"wizard":
if (len(self.actual_arguments) < 3) or (self.actual_arguments[2].startswith(u"-")):
return self.print_help()
config_string = self.actual_arguments[1]
container_path = self.actual_arguments[2]
if not self.check_input_file(container_path):
return self.ERROR_EXIT_CODE
result = validator.check_container(container_path, config_string=config_string)
msg = "container with configuration string from wizard"
else:
return self.print_help()
if result.passed:
self.print_success(u"Valid %s" % msg)
for warning in result.warnings:
self.print_warning(u"%s" % warning)
return self.NO_ERROR_EXIT_CODE
else:
self.print_error(u"Invalid %s" % msg)
for error in result.errors:
self.print_error(u"%s" % error)
return self.ERROR_EXIT_CODE
示例6: load_job_from_container
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [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
示例7: perform_command
# 需要導入模塊: from aeneas.validator import Validator [as 別名]
# 或者: from aeneas.validator.Validator import check_container [as 別名]
def perform_command(self):
"""
Perform command and return the appropriate exit code.
:rtype: int
"""
if len(self.actual_arguments) < 2:
return self.print_help()
container_path = self.actual_arguments[0]
output_directory_path = self.actual_arguments[1]
config_string = None
if (len(self.actual_arguments)) > 2 and (not self.actual_arguments[2].startswith(u"-")):
config_string = self.actual_arguments[2]
validate = not self.has_option(u"--skip-validator")
if self.has_option(u"--cewsubprocess"):
self.rconf[RuntimeConfiguration.CEW_SUBPROCESS_ENABLED] = True
if not self.check_input_file_or_directory(container_path):
return self.ERROR_EXIT_CODE
if not self.check_output_directory(output_directory_path):
return self.ERROR_EXIT_CODE
if validate:
try:
self.print_info(u"Validating the container (specify --skip-validator to bypass)...")
validator = Validator(rconf=self.rconf, logger=self.logger)
result = validator.check_container(container_path, config_string=config_string)
if not result.passed:
self.print_error(u"The given container is not valid:")
self.print_error(result.pretty_print())
return self.ERROR_EXIT_CODE
self.print_info(u"Validating the container... done")
except Exception as exc:
self.print_error(u"An unexpected error occurred while validating the container:")
self.print_error(u"%s" % exc)
return self.ERROR_EXIT_CODE
try:
self.print_info(u"Loading job from container...")
executor = ExecuteJob(rconf=self.rconf, logger=self.logger)
executor.load_job_from_container(container_path, config_string)
self.print_info(u"Loading job from container... done")
except Exception as exc:
self.print_error(u"An unexpected error occurred while loading the job:")
self.print_error(u"%s" % exc)
return self.ERROR_EXIT_CODE
try:
self.print_info(u"Executing...")
executor.execute()
self.print_info(u"Executing... done")
except Exception as exc:
self.print_error(u"An unexpected error occurred while executing the job:")
self.print_error(u"%s" % exc)
return self.ERROR_EXIT_CODE
try:
self.print_info(u"Creating output container...")
path = executor.write_output_container(output_directory_path)
self.print_info(u"Creating output container... done")
self.print_success(u"Created output file '%s'" % path)
executor.clean(True)
return self.NO_ERROR_EXIT_CODE
except Exception as exc:
self.print_error(u"An unexpected error occurred while writing the output container:")
self.print_error(u"%s" % exc)
return self.ERROR_EXIT_CODE