Commits

Michał Górny committed eec2df2

LILO: pass file contents into matching function.

  • Participants
  • Parent commits bec1171

Comments (0)

Files changed (1)

ecleankernel/bootloader/lilo.py

 		self._kernel_re = re.compile(self.kernel_re,
 				re.MULTILINE | re.IGNORECASE)
 
-	def _get_kernels(self, f):
+	def _get_kernels(self, content):
 		debug = self._debug
 
 		debug.indent(heading = 'matching...')
 		try:
-			for m in self._kernel_re.finditer(f.read()):
+			for m in self._kernel_re.finditer(content):
 				path = m.group('path')
 				debug.printf('regexp matched path %s', path)
 				debug.indent()
 				debug.outdent()
 				yield path
 		finally:
-			f.close()
 			debug.outdent()
 
 	def __call__(self, path = None):
-		f = open(path or self.def_path)
-		self._debug.print('%s found' % (path or self.def_path))
-
-		return self._get_kernels(f)
+		with open(path or self.def_path) as f:
+			self._debug.print('%s found' % (path or self.def_path))
+			return self._get_kernels(f.read())