eclean-kernel / ecleankernel / bootloader / lilo.py

#	vim:fileencoding=utf-8
# (c) 2011 Michał Górny <mgorny@gentoo.org>
# Released under the terms of the 2-clause BSD license.

from __future__ import print_function

from .common import BootloaderNotFound

import errno, re

class LILO(object):
	name = 'lilo'
	kernel_re = r'^\s*image\s*=\s*(?P<path>.+)\s*$'
	def_path = '/etc/lilo.conf'

	def __init__(self, debug = False, path = None):
		self._debug = debug
		self._kernel_re = re.compile(self.kernel_re,
				re.MULTILINE | re.IGNORECASE)
		paths = path or self.def_path
		if not isinstance(paths, tuple):
			paths = (paths,)

		for p in paths:
			try:
				with open(p) as f:
					debug.print('%s found' % p)
					self.path = p
					self._content = f.read()
			except IOError as e:
				if e.errno != errno.ENOENT:
					raise
		else:
			raise BootloaderNotFound()

	def _get_kernels(self, content):
		debug = self._debug

		debug.indent(heading = 'matching...')
		try:
			for m in self._kernel_re.finditer(content):
				path = m.group('path')
				debug.printf('regexp matched path %s', path)
				debug.indent()
				debug.printf('from line: %s', m.group(0))
				debug.outdent()
				yield path
		finally:
			debug.outdent()

	def __call__(self):
		return self._get_kernels(self._content)
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 ProjectModifiedEvent.java.
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.