Skip to content

Commit

Permalink
Get the current_kernel_version from regex the os.uname()[2], this fix…
Browse files Browse the repository at this point in the history
… the bug #1051717 finally
  • Loading branch information
tualatrix committed Sep 30, 2012
1 parent 43e06a5 commit 13b953d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions tests/test_janitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import shutil
import unittest

from ubuntutweak.janitor.oldkernel_plugin import OldKernelPlugin
Expand All @@ -10,6 +8,10 @@ def setUp(self):
self.oldkernel_plugin.current_kernel_version = '2.6.38-10'

def test_oldkernel(self):
self.assertEqual(self.oldkernel_plugin.p_kernel_version.findall('3.6.0-030600rc3')[0], '3.6.0-030600')
self.assertEqual(self.oldkernel_plugin.p_kernel_version.findall('3.6.0-0306rc3')[0], '3.6.0-0306')
self.assertEqual(self.oldkernel_plugin.p_kernel_version.findall('3.6.0-03rc3')[0], '3.6.0-03')

self.assertTrue(self.oldkernel_plugin.is_old_kernel_package('linux-headers-2.6.35-28'))
self.assertTrue(self.oldkernel_plugin.is_old_kernel_package('linux-image-2.6.38-9-generic'))
self.assertFalse(self.oldkernel_plugin.is_old_kernel_package('linux-image-2.6.38-10'))
Expand Down
14 changes: 7 additions & 7 deletions ubuntutweak/janitor/oldkernel_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class OldKernelPlugin(JanitorPlugin):
__title__ = _('Old Kernel')
__category__ = 'system'

p_kernel_version = re.compile('[.\d]+-\d+')
p_kernel_package = re.compile('linux-[a-z\-]+')

def __init__(self):
JanitorPlugin.__init__(self)
self.current_kernel_version = '-'.join(os.uname()[2].split('-')[:2])
self.current_kernel_version = self.p_kernel_version.findall('-'.join(os.uname()[2].split('-')[:2]))[0]
log.debug("the current_kernel_version is %s" % self.current_kernel_version)

def get_cruft(self):
Expand Down Expand Up @@ -61,23 +64,20 @@ def on_clean_finished(self, transaction, status, parent):
self.emit('all_cleaned', True)

def is_old_kernel_package(self, pkg):
p_kernel_version = re.compile('[.\d]+-\d+')
p_kernel_package = re.compile('linux-[a-z\-]+')

basenames = ['linux-image', 'linux-image-extra', 'linux-headers',
'linux-image-debug', 'linux-ubuntu-modules',
'linux-header-lum', 'linux-backport-modules',
'linux-header-lbm', 'linux-restricted-modules']

if pkg.startswith('linux'):
package = p_kernel_package.findall(pkg)
package = self.p_kernel_package.findall(pkg)
if package:
package = package[0].rstrip('-')
else:
return False

if package in basenames:
match = p_kernel_version.findall(pkg)
match = self.p_kernel_version.findall(pkg)
if match and self._compare_kernel_version(match[0]):
return True
return False
Expand All @@ -87,7 +87,7 @@ def _compare_kernel_version(self, version):
c1, c2 = self.current_kernel_version.split('-')
p1, p2 = version.split('-')
if c1 == p1:
if int(c2[:6]) > int(p2[:6]):
if int(c2) > int(p2):
return True
else:
return False
Expand Down

0 comments on commit 13b953d

Please sign in to comment.