Beispiel #1
0
def main(argv):
    """Parse command-line flags and run XML validator.

  Args:
    argv: The program argument vector (excluding the script name)
  """
    start_time = time.time()

    options = LoadOptionsFromFlags(argv)
    file_paths = GetInputFilePath(options['file_path'])

    try:
        xml_file = open(file_paths['xml_file_path'], 'r')
    except IOError as io_error:
        print 'Error opening XML file\n\n%s' % io_error
        sys.exit(2)

    if options['verbose']:
        print '==== Checking XML file against DSPL schema....'

    result = xml_validation.RunValidation(xml_file, verbose=options['verbose'])

    print result

    if 'validates successfully' not in result:
        # Stop if XML validation not successful
        sys.exit(2)

    if options['checking_level'] != 'schema_only':
        if options['verbose']:
            print '\n==== Parsing DSPL dataset....'

        if options['checking_level'] == 'full':
            full_data_check = True
        else:
            full_data_check = False

        try:
            dataset = dspl_model_loader.LoadDSPLFromFiles(
                file_paths['xml_file_path'], load_all_data=full_data_check)
        except dspl_model_loader.DSPLModelLoaderError as loader_error:
            print 'Error while trying to parse DSPL dataset\n\n%s' % loader_error
            sys.exit(2)

        if options['verbose']:
            print 'Parsing completed.'

            if full_data_check:
                print '\n==== Checking DSPL model and data....'
            else:
                print '\n==== Checking DSPL model....'

        dspl_validator = dspl_validation.DSPLDatasetValidator(
            dataset, full_data_check=full_data_check)

        print dspl_validator.RunValidation(options['verbose'])

    xml_file.close()

    if file_paths['zip_dir']:

        shutil.rmtree(file_paths['zip_dir'])

    if options['verbose']:
        print '\nCompleted in %0.2f seconds' % (time.time() - start_time)
Beispiel #2
0
 def setUp(self):
     self.dataset = dspl_model_loader.LoadDSPLFromFiles(
         os.path.join(
             os.path.split(__file__)[0], 'test_dataset', 'dataset.xml'))