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 test_check_job_configuration_05(self): logger = Logger() validator = Validator(logger=logger) string = "malformed=" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_01(self): logger = Logger() validator = Validator(logger=logger) string = u"dummy config string with bad encoding é".encode("latin-1") result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_02(self): logger = Logger() validator = Validator(logger=logger) string = "dummy config string with ~ reserved characters" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_17(self): logger = Logger() validator = Validator(logger=logger) string = "job_language=it|os_job_file_name=output.zip|os_job_file_container=zip|os_job_file_hierarchy_type=flat" result = validator.check_job_configuration(string) self.assertTrue(result.passed) self.assertEqual(len(result.errors), 0)
def test_check_job_configuration_14(self): logger = Logger() validator = Validator(logger=logger) string = "job_language=it|os_job_file_name=output.zip|os_job_file_container=zip|is_hierarchy_type=paged" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_08(self): logger = Logger() validator = Validator(logger=logger) string = "job_language=it|os_job_file_name=output.zip" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_07(self): logger = Logger() validator = Validator(logger=logger) string = "job_language=it|missing=other" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def test_check_job_configuration_06(self): logger = Logger() validator = Validator(logger=logger) string = "not=relevant|config=string" result = validator.check_job_configuration(string) self.assertFalse(result.passed) self.assertGreater(len(result.errors), 0)
def jc(self, string, expected): validator = Validator() result = validator.check_job_configuration(string) self.assertEqual(result.passed, expected) if expected: self.assertEqual(len(result.errors), 0) else: self.assertGreater(len(result.errors), 0)
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