|
|
# version is None and error is a string | # version is None and error is a string |
# | # |
def ExtractKernelVersion(base_dir): | def ExtractKernelVersion(base_dir): |
pathname = os.path.join(base_dir, 'include/linux/version.h') |
lines = [] |
|
pathname = os.path.join(base_dir, 'Makefile') |
try: | try: |
lines = open(pathname, 'r').readlines() |
f = open(pathname, 'r') |
except OSError, details: | except OSError, details: |
return (None, str(details)) | return (None, str(details)) |
except IOError, details: | except IOError, details: |
return (None, str(details)) | return (None, str(details)) |
| |
|
try: |
|
for i in range(4): |
|
lines.append(f.readline()) |
|
except OSError, details: |
|
return (None, str(details)) |
|
except IOError, details: |
|
return (None, str(details)) |
|
|
lines = map(string.strip, lines) | lines = map(string.strip, lines) |
| |
version = '' | version = '' |
| |
for line in lines: | for line in lines: |
items = string.split(line, ' ', 2) |
# split on the '=' then remove annoying whitespace |
if items[0] == '#define' and \ |
items = string.split(line, '=') |
items[1] == 'UTS_RELEASE': |
items = map(string.strip, items) |
version = items[2] # - may be wrapped in quotes |
if items[0] == 'VERSION' or \ |
break |
items[0] == 'PATCHLEVEL': |
|
version += items[1] |
if version == '': |
version += "." |
return (None, "Unable to locate UTS_RELEASE in %s" % (pathname)) |
elif items[0] == 'SUBLEVEL': |
|
version += items[1] |
|
elif items[0] == 'EXTRAVERSION' and \ |
|
items[-1] != items[0]: |
|
version += items[1] |
| |
if version[0] == '"' and version[-1] == '"': |
|
version = version[1:-1] |
|
return (version,None) | return (version,None) |
| |
aumtime=0 | aumtime=0 |