Michał Górny avatar Michał Górny committed b75e353

Support excluding kernel parts from removal.

Comments (0)

Files changed (2)


 from optparse import OptionParser
-from .kernel import find_kernels
+from .kernel import find_kernels, Kernel
 from .process import get_removal_list
 ecleankern_desc = '''
 	parser.add_option('-p', '--pretend',
 			dest='pretend', action='store_true', default=False,
 			help='Print the list of kernels to be removed and exit')
+	parser.add_option('-x', '--exclude',
+			dest='exclude', default='',
+			help='Exclude kernel parts from being removed (comma-separated, supported parts: %s)'
+				% ', '.join(Kernel.parts))
 	(opts, args) = parser.parse_args(argv[1:])
+	exclusions = frozenset(opts.exclude.split(','))
+	for x in exclusions:
+		if not x:
+			pass
+		elif x not in Kernel.parts:
+			parser.error('Invalid kernel part: %s' % x)
+		elif x == 'vmlinuz':
+			parser.error('Kernel exclusion unsupported')
 	debug = ConsoleDebugger() if opts.debug else NullDebugger()
-	kernels = find_kernels()
+	kernels = find_kernels(exclusions = exclusions)
 	if opts.listkern:
 		for k in kernels:


 	buf = f.read(0x100) # XXX
 	return str(buf.split(b' ', 1)[0])
-def find_kernels():
+def find_kernels(exclusions = ()):
 	""" Find all files and directories related to installed kernels. """
 	globs = (
 	kernels = KernelDict()
 	for cat, g in globs:
+		if cat in exclusions:
+			continue
 		for m in glob('%s*' % g):
 			kv = m[len(g):]
 			if cat == 'initramfs' and kv.endswith('.img'):
 				realkv = get_real_kv(path)
 				moduledir = os.path.join('/lib/modules', realkv)
 				builddir = paths[os.path.join(moduledir, 'build')]
-				if os.path.isdir(moduledir):
+				if 'modules' not in exclusions and os.path.isdir(moduledir):
 					newk.modules = paths[moduledir]
-				if os.path.isdir(builddir):
+				if 'build' not in exclusions and os.path.isdir(builddir):
 					newk.build = paths[builddir]
 	# fill .old files
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.