Michał Górny committed 095f651

Add initial support for parsing grub2 config.

Comments (0)

Files changed (2)


+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <>
+# Released under the terms of the 2-clause BSD license.
+from __future__ import print_function
+import os.path, re
+def get_grub2_kernels(debug):
+	kernel_re = re.compile(r'^\s*linux\s*(\([^)]+\))?(\S+)',
+	f = open('/boot/grub/grub.cfg')
+	debug.print('grub.cfg found')
+	def _get_kernels(f):
+		debug.indent(heading = 'matching grub.cfg')
+		try:
+			for m in kernel_re.finditer(
+				path =
+				debug.printf('regexp matched path %s', path)
+				debug.indent()
+				debug.printf('from line: %s',
+				if os.path.relpath(path, '/boot').startswith('..'):
+					path = os.path.join('/boot', os.path.relpath(path, '/'))
+					debug.printf('appending /boot, path now: %s', path)
+				debug.outdent()
+				yield path
+		finally:
+			debug.outdent()
+			f.close()
+	return _get_kernels(f)


 import errno, os, os.path, re
 from .grub import get_grub_kernels
+from .grub2 import get_grub2_kernels
 from .lilo import get_lilo_kernels
 from .yaboot import get_yaboot_kernels
 from .symlinks import get_vmlinuz_symlinks
 bootloaders = (
 	('lilo', get_lilo_kernels),
+	('grub2', get_grub2_kernels),
 	('grub', get_grub_kernels),
 	('yaboot', get_yaboot_kernels),
 	('symlinks', get_vmlinuz_symlinks),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.