diff options
author | Jesse Jaggars <jjaggars@redhat.com> | 2012-03-14 19:09:06 -0500 |
---|---|---|
committer | Jesse Jaggars <jjaggars@redhat.com> | 2012-03-14 19:09:06 -0500 |
commit | 44ddbc54cffe2d1adb51ed805901a9124ca71f01 (patch) | |
tree | 15709d688edb21f55b101d5040f40de6a8ba22bf | |
parent | 20e9d49b29a63614ee173d7773113aa610252936 (diff) | |
download | sos-44ddbc54cffe2d1adb51ed805901a9124ca71f01.tar.gz |
fixing some python2.5 compatibility issues
-rw-r--r-- | sos/plugins/__init__.py | 14 | ||||
-rw-r--r-- | sos/policies/__init__.py | 16 | ||||
-rw-r--r-- | tests/plugin_tests.py | 10 |
3 files changed, 30 insertions, 10 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index fc3a4ed0..e288156e 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -23,6 +23,7 @@ # pylint: disable-msg = R0201 # pylint: disable-msg = W0611 # pylint: disable-msg = W0613 +from __future__ import with_statement from sos.utilities import sosGetCommandOutput, import_module, grep, fileobj, tail from sos import _sos as _ @@ -81,6 +82,13 @@ def regex_findall(regex, fname): except AttributeError: return [] +def mangle_command(command): + # FIXME: this can be improved + mangledname = re.sub(r"^/(usr/|)(bin|sbin)/", "", command) + mangledname = re.sub(r"[^\w\-\.\/]+", "_", mangledname) + mangledname = re.sub(r"/", ".", mangledname).strip(" ._-")[0:64] + return mangledname + class PluginException(Exception): pass @@ -424,11 +432,7 @@ class Plugin(object): return grep(regexp, *fnames) def mangleCommand(self, exe): - # FIXME: this can be improved - mangledname = re.sub(r"^/(usr/|)(bin|sbin)/", "", exe) - mangledname = re.sub(r"[^\w\-\.\/]+", "_", mangledname) - mangledname = re.sub(r"/", ".", mangledname).strip(" ._-")[0:64] - return mangledname + return mangle_command(exe) def makeCommandFilename(self, exe): """The internal function to build up a filename based on a command.""" diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 80a2ed40..32ecb0a0 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import os import re import platform @@ -129,14 +131,20 @@ No changes will be made to your system. self.package_manager = PackageManager() self._valid_subclasses = [] - @property - def valid_subclasses(self): + def get_valid_subclasses(self): return [IndependentPlugin] + self._valid_subclasses - @valid_subclasses.setter - def valid_subclasses(self, subclasses): + def set_valid_subclasses(self, subclasses): self._valid_subclasses = subclasses + def del_valid_subclasses(self): + del self._valid_subclasses + + valid_subclasses = property(get_valid_subclasses, + set_valid_subclasses, + del_valid_subclasses, + "list of subclasses that this policy can process") + def check(self): """ This function is responsible for determining if the underlying system diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index 87940b8e..a3055543 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -3,7 +3,7 @@ import os import tempfile from StringIO import StringIO -from sos.plugins import Plugin, regex_findall, sosRelPath +from sos.plugins import Plugin, regex_findall, sosRelPath, mangle_command from sos.utilities import Archive PATH = os.path.dirname(__file__) @@ -126,6 +126,14 @@ class PluginToolTests(unittest.TestCase): path2 = "foo/lib/boo" self.assertEquals(sosRelPath(path1, path2), "foo/lib/boo") + def test_mangle_command(self): + self.assertEquals("foo", mangle_command("/usr/bin/foo")) + self.assertEquals("foo_-x", mangle_command("/usr/bin/foo -x")) + self.assertEquals("foo_--verbose", mangle_command("/usr/bin/foo --verbose")) + self.assertEquals("foo_.path.to.stuff", mangle_command("/usr/bin/foo /path/to/stuff")) + expected = "foo_.path.to.stuff.this.is.very.long.and.i.only.expect.part.of.it.maybe.this.is.enough.i.hope.so"[0:64] + self.assertEquals(expected, mangle_command("/usr/bin/foo /path/to/stuff/this/is/very/long/and/i/only/expect/part/of/it/maybe/this/is/enough/i/hope/so")) + class PluginTests(unittest.TestCase): |