from mmap import mmap, ACCESS_READ 
from sys import exit


def is_covered():
    '''
    Checking a commit coverage report generated by diff-cover, and parsing
    to see if any lines in the commit are not ocvered. Exiting with -1 if uncovered lines
    are found
    '''

    cov_xml = open('commit_coverage.html', 'r+') 
    cov_map = mmap(cov_xml.fileno(), 0)

    missing = b'Missing</b>: ' 
    missing_loc = cov_map.find(missing)

    if missing_loc != -1:
        cov_map.seek(missing_loc + len(missing)) 

        if int(cov_map.read(2)) > 0:
            print ('Some lines not covered in commit')
            exit(-1)



if __name__ == '__main__':

    is_covered()
