1. Michał Górny
  2. eclean-kernel

Commits

Michał Górny  committed 999173b

Support non-pretend runs (but not implement removal yet).

  • Participants
  • Parent commits b996e54
  • Branches master

Comments (0)

Files changed (1)

File ecleankernel/cli.py

View file
  • Ignore whitespace
 # (c) 2010 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
+from optparse import OptionParser
+
 from .kernel import find_kernels
 from .process import get_removal_list
 
 def main(argv):
-	k = find_kernels()
-	removals = get_removal_list(k)
+	parser = OptionParser()
+	parser.add_option('-p', '--pretend',
+			dest='pretend', action='store_true', default=False,
+			help='Print the list of kernels to be removed and exit')
+	(opts, args) = parser.parse_args(argv[1:])
 
-	if removals:
-		print('These are the kernels which will be removed:')
-	else:
+	kernels = find_kernels()
+	removals = get_removal_list(kernels)
+
+	if not removals:
 		print('No outdated kernels found.')
+	elif opts.pretend:
+		print('These are the kernels which would be removed:')
 
-	for k, reason in removals:
-		print('- %s: %s' % (k.version, ', '.join(reason)))
+		for k, reason in removals:
+			print('- %s: %s' % (k.version, ', '.join(reason)))
+	else:
+		for k, reason in removals:
+			print('* Removing kernel %s (%s)' % (k.version, ', '.join(reason)))
+			del kernels[k.version]
 
 	return 0