aboutsummaryrefslogtreecommitdiffstats
path: root/chapter10/kernel/kernel_version.py
diff options
context:
space:
mode:
Diffstat (limited to 'chapter10/kernel/kernel_version.py')
-rwxr-xr-xchapter10/kernel/kernel_version.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/chapter10/kernel/kernel_version.py b/chapter10/kernel/kernel_version.py
new file mode 100755
index 000000000..764bb2d33
--- /dev/null
+++ b/chapter10/kernel/kernel_version.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+def kernel_version(path):
+ version = None
+ patchlevel = None
+ sublevel = None
+
+ with open(path + 'Makefile') as f:
+ for line in f:
+ if line.startswith('VERSION ='):
+ version = line[len('VERSION ='):].strip()
+ elif line.startswith('PATCHLEVEL ='):
+ patchlevel = line[len('PATCHLEVEL ='):].strip()
+ elif line.startswith('SUBLEVEL ='):
+ sublevel = line[len('SUBLEVEL ='):].strip()
+
+ assert(version and patchlevel and sublevel)
+ return '.'.join([version, patchlevel, sublevel])
+
+if __name__ == '__main__':
+ from sys import argv
+
+ path = argv[1]
+ if path[:-1] != '/':
+ path += '/'
+
+ print(kernel_version(path))