Commits

Michał Górny committed 458fbd9

Bootloaders: delay returning the generator until file is open.

  • Participants
  • Parent commits 9009fc6

Comments (0)

Files changed (2)

File ecleankernel/grub.py

 
 	f = open('/boot/grub/grub.conf')
 	if debug:
-		print('*** grub.conf %sfound' % ('' if f else 'not '))
-	for m in kernel_re.finditer(f.read()):
-		path = m.group(1)
-		if debug:
-			print('**** regexp matched path %s' % path)
-			print('     from line: %s' % m.group(0))
-		if os.path.relpath(path, '/boot').startswith('..'):
-			path = os.path.join('/boot', path)
-			print('***** appending /boot, path now: %s' % path)
-		yield path
-	f.close()
+		print('*** grub.conf found')
+
+	def _get_kernels(f):
+		try:
+			for m in kernel_re.finditer(f.read()):
+				path = m.group(1)
+				if debug:
+					print('**** regexp matched path %s' % path)
+					print('     from line: %s' % m.group(0))
+				if os.path.relpath(path, '/boot').startswith('..'):
+					path = os.path.join('/boot', path)
+					print('***** appending /boot, path now: %s' % path)
+				yield path
+		finally:
+			f.close()
+
+	return _get_kernels(f)

File ecleankernel/lilo.py

 			re.MULTILINE | re.IGNORECASE)
 
 	f = open('/etc/lilo.conf')
-	for m in kernel_re.finditer(f.read()):
-		yield m.group(1)
-	f.close()
+
+	def _get_kernels(f):
+		try:
+			for m in kernel_re.finditer(f.read()):
+				yield m.group(1)
+		finally:
+			f.close()
+
+	return _get_kernels(f)