Commits

Michał Górny committed 2430b36

Report real KV in --list-kernels.

  • Participants
  • Parent commits 2dd3cc7

Comments (0)

Files changed (2)

ecleankernel/cli.py

 
 		if opts.listkern:
 			for k in kernels:
-				print('%s:' % k.version)
+				print('%s [%s]:' % (k.version, k.real_kv))
 				for key in k.parts:
 					val = getattr(k, key)
 					if val is not None:

ecleankernel/kernel.py

 			'modules', 'build')
 
 	@property
+	def real_kv(self):
+		""" Obtain the KV from the kernel, as used by it. """
+		vmlinuz = self.vmlinuz
+		if vmlinuz is None:
+			return None
+
+		f = open(vmlinuz, 'rb')
+		f.seek(0x200)
+		buf = f.read(0x10)
+		if buf[2:6] != b'HdrS':
+			raise NotImplementedError('Invalid magic for kernel file %s (!= HdrS)'
+					% path)
+		offset = struct.unpack_from('H', buf, 0x0e)[0]
+		f.seek(offset - 0x10, 1)
+		buf = f.read(0x100) # XXX
+		return str(buf.split(b' ', 1)[0])
+
+	@property
 	def mtime(self):
 		# prefer vmlinuz, fallback to anything
 		# XXX: or maybe max()? min()?
 	def __repr__(self):
 		return 'KernelDict(%s)' % ','.join(['\n\t%s' % repr(x) for x in self.values()])
 
-def get_real_kv(path):
-	f = open(path, 'rb')
-	f.seek(0x200)
-	buf = f.read(0x10)
-	if buf[2:6] != b'HdrS':
-		raise NotImplementedError('Invalid magic for kernel file %s (!= HdrS)'
-				% path)
-	offset = struct.unpack_from('H', buf, 0x0e)[0]
-	f.seek(offset - 0x10, 1)
-	buf = f.read(0x100) # XXX
-	return str(buf.split(b' ', 1)[0])
-
 def find_kernels(exclusions = ()):
 	""" Find all files and directories related to installed kernels. """
 
 					if newk.build:
 						kernels['%s.old' % kv].build = builddir
 			if cat == 'vmlinuz':
-				realkv = get_real_kv(path)
+				realkv = newk.real_kv
 				moduledir = os.path.join('/lib/modules', realkv)
 				builddir = paths[os.path.join(moduledir, 'build')]
 				if 'modules' not in exclusions and os.path.isdir(moduledir):