#!/usr/bin/env python2.7
import sys
import argparse
from ucscGb.encode import cv

class validate(object):
    '''validation script that calls cv.validate and then puts all its errors into a list'''

    def __init__(self):
    
        parser = argparse.ArgumentParser(description = 'Validates the controlled vocabulary file')
        parser.add_argument('-c', '--cvPath', help='Overrides the default cv path ~/kent/src/hg/makeDb/trackDb/cv/alpha/cv.ra')
        parser.add_argument('-p', '--protocolPath', help='Overrides the default protocol path ~/htdocsExtras/ENCODE/')
        parser.add_argument('-l', '--loose', action='store_true', default=False, help='Suppress all warnings, only display breaking errors')
        
        args = parser.parse_args(sys.argv[1:])
        
        self.loose = args.loose
        self.errors = list()
        self.cv = cv.CvFile(args.cvPath, self.addtoerrs, args.protocolPath)  
        self.cv.validate()
        
        
        for err in self.errors:
            print err
            
    def addtoerrs(self, exception):
        if not self.loose or exception.strict:
            self.errors.append(exception)

if __name__ == '__main__':
    val = validate()


