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
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
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