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

Commits

Michał Górny  committed 9519270

Initial version, grabbing kernel list.

  • Participants
  • Branches master

Comments (0)

Files changed (7)

File COPYING

View file
  • Ignore whitespace
+Copyright (c) 2011, Michał Górny
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

File MANIFEST.in

View file
  • Ignore whitespace
+include COPYING

File eclean-kernel

View file
  • Ignore whitespace
+#!/usr/bin/python
+#	vim:fileencoding=utf-8
+# Remove old kernel versions.
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+import sys
+
+try:
+	from ecleankernel.cli import main
+except ImportError:
+	import os.path
+	sys.path.insert(0, os.path.dirname(__file__))
+	# Ensure a clean reload from the new location.
+	if 'ecleankernel' in sys.modules:
+		try: # py3 compat
+			from imp import reload
+		except ImportError:
+			pass
+
+		reload(sys.modules['ecleankernel'])
+		del sys.modules['ecleankernel']
+	from ecleankernel.cli import main
+
+if __name__ == '__main__':
+	sys.exit(main(sys.argv))

File ecleankernel/__init__.py

View file
  • Ignore whitespace
+#	vim:fileencoding=utf-8
+# (c) 2010 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+PV = '0'

File ecleankernel/cli.py

View file
  • Ignore whitespace
+#	vim:fileencoding=utf-8
+# (c) 2010 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from .kernel import find_kernels
+
+def main(argv):
+	print find_kernels()
+
+	return 0

File ecleankernel/kernel.py

View file
  • Ignore whitespace
+#	vim:fileencoding=utf-8
+# (c) 2010 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from collections import defaultdict
+from glob import glob
+
+class Kernel(object):
+	""" An object representing a single kernel version. """
+
+	def __init__(self, version):
+		self.version = version
+		self.vmlinuz = None
+		self.systemmap = None
+		self.config = None
+		self.modules = None
+
+	def __repr__(self):
+		return "Kernel(%s, '%s%s%s%s')" % (repr(self.version),
+				'V' if self.vmlinuz else ' ',
+				'S' if self.systemmap else ' ',
+				'C' if self.config else ' ',
+				'M' if self.modules else ' ')
+
+class KernelDict(defaultdict):
+	def __missing__(self, kv):
+		k = Kernel(kv)
+		self[kv] = k
+		return k
+
+	def __repr__(self):
+		return 'KernelDict(%s)' % ','.join(['\n\t%s' % repr(x) for x in self.values()])
+
+def find_kernels():
+	""" Find all files and directories related to installed kernels. """
+
+	globs = {
+		'vmlinuz': '/boot/vmlinuz-',
+		'systemmap': '/boot/System.map-',
+		'config': '/boot/config-',
+		'modules': '/lib/modules/'
+	}
+
+	kernels = KernelDict()
+	for cat, g in globs.items():
+		for m in glob('%s*' % g):
+			kv = m[len(g):]
+			setattr(kernels[kv], cat, m)
+
+	return kernels

File setup.py

View file
  • Ignore whitespace
+#!/usr/bin/python
+#	vim:fileencoding=utf-8
+# (c) 2010 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from distutils.core import setup
+
+import os.path, sys
+
+sys.path.insert(0, os.path.dirname(__file__))
+try:
+	from ecleankernel import PV
+except ImportError:
+	PV = 'unknown'
+
+setup(
+		name = 'eclean-kernel',
+		version = PV,
+		author = 'Michał Górny',
+		author_email = 'mgorny@gentoo.org',
+		url = 'http://github.com/mgorny/eclean-kernel',
+
+		packages = ['ecleankernel'],
+		scripts = ['eclean-kernel'],
+
+		classifiers = [
+			'Development Status :: 2 - Pre-Alpha',
+			'Environment :: Console',
+			'Intended Audience :: System Administrators',
+			'License :: OSI Approved :: BSD License',
+			'Operating System :: POSIX',
+			'Programming Language :: Python',
+			'Topic :: System :: Installation/Setup'
+		]
+)