Commits

Michał Górny  committed dd1441d

Add debug for grub.

  • Participants
  • Parent commits e35a0d6

Comments (0)

Files changed (5)

File ecleankernel/cli.py

 	parser.add_option('-d', '--destructive',
 			dest='destructive', action='store_true', default=False,
 			help='Destructive mode: remove kernels even when referenced by bootloader')
+	parser.add_option('-D', '--debug',
+			dest='debug', action='store_true', default=False,
+			help='Enable debugging output')
 	parser.add_option('-n', '--num',
 			dest='num', type='int', default=0,
 			help='Leave only newest NUM kernels (by mtime)')
 	removals = get_removal_list(kernels,
 			limit = None if opts.all else opts.num,
 			bootloader = opts.bootloader,
-			destructive = opts.destructive)
+			destructive = opts.destructive,
+			debug = opts.debug)
 
 	if not removals:
 		print('No outdated kernels found.')

File ecleankernel/grub.py

 
 from .util import open_if_exists
 
-def get_grub_kernels():
+def get_grub_kernels(debug = False):
 	kernel_re = re.compile(r'^\s*kernel\s*(\S+)',
 			re.MULTILINE | re.IGNORECASE)
 
 	f = open_if_exists('/boot/grub/grub.conf')
+	if debug:
+		print('*** grub.conf %sfound' % ('' if f else 'not '))
 	if f:
 		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()

File ecleankernel/lilo.py

 
 from .util import open_if_exists
 
-def get_lilo_kernels():
+def get_lilo_kernels(debug = False):
 	kernel_re = re.compile(r'^\s*image\s*=\s*(.+)\s*$',
 			re.MULTILINE | re.IGNORECASE)
 

File ecleankernel/process.py

 		if k.vmlinuz is None:
 			yield k
 
-def get_removal_list(kernels, limit = 0, bootloader = 'auto', destructive = False):
+def get_removal_list(kernels, limit = 0, bootloader = 'auto', destructive = False, debug = False):
 	""" Get a list of outdated kernels to remove. With explanations. """
 
+	if debug:
+		print('* In get_removal_list()')
+
 	out = RemovedKernelDict()
 	for k in remove_stray(kernels):
 		out.add(k, 'vmlinuz does not exist')
 			used = ()
 			for bl, getfunc in bootloaders:
 				if bootloader in ('auto', bl):
+					if debug:
+						print('** Trying bootloader %s' % bl)
 					try:
-						used = getfunc()
+						used = getfunc(debug = debug)
 					except Exception:
 						pass
 					else:

File ecleankernel/symlinks.py

 
 import os.path
 
-def get_vmlinuz_symlinks():
+def get_vmlinuz_symlinks(debug = False):
 	for fn in ('vmlinuz', 'vmlinux', 'kernel', 'bzImage'):
 		for suffix in ('', '.old'):
 			f = '/boot/%s%s' % (fn, suffix)