'Check Makefile and .config to return kernel version'

def get_kernel_build_ver(self):

    version = patchlevel = sublevel = extraversion = localversion = ''
    for line in open((self.build_dir + '/Makefile'), 'r').readlines():
        if line.startswith('VERSION'):
            version = line[(line.index('=') + 1):].strip()
        if line.startswith('PATCHLEVEL'):
            patchlevel = line[(line.index('=') + 1):].strip()
        if line.startswith('SUBLEVEL'):
            sublevel = line[(line.index('=') + 1):].strip()
        if line.startswith('EXTRAVERSION'):
            extraversion = line[(line.index('=') + 1):].strip()
    for line in open((self.build_dir + '/.config'), 'r').readlines():
        if line.startswith('CONFIG_LOCALVERSION='):
            localversion = line.rstrip().split('"')[1]
    return ('%s.%s.%s%s%s' % (version, patchlevel, sublevel, extraversion, localversion))
