diff options
author | Jesse Jaggars <jjaggars@redhat.com> | 2012-03-08 12:15:16 -0600 |
---|---|---|
committer | Jesse Jaggars <jjaggars@redhat.com> | 2012-03-08 12:15:16 -0600 |
commit | bbc6890f9ef4a7612c6960a522df4b0cd099054e (patch) | |
tree | 641b4cece1b3df69130796d985643f8874a21ae6 | |
parent | 237b0157e98c6412c77b32d6d1cedc7afd0b02e4 (diff) | |
download | sos-bbc6890f9ef4a7612c6960a522df4b0cd099054e.tar.gz |
fixing fileGrep to pass multiple search paths better and we handle non-existant files as well
-rw-r--r-- | sos/plugins/__init__.py | 2 | ||||
-rw-r--r-- | sos/utilities.py | 5 | ||||
-rw-r--r-- | tests/utilities_tests.py | 4 |
3 files changed, 9 insertions, 2 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index b9be263a..3b12fd6b 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -394,7 +394,7 @@ class Plugin(object): def fileGrep(self, regexp, *fnames): """Returns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line""" - return grep(regexp, fnames) + return grep(regexp, *fnames) def mangleCommand(self, exe): # FIXME: this can be improved diff --git a/sos/utilities.py b/sos/utilities.py index e705ae7d..e0d57dfe 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -42,7 +42,10 @@ import time def fileobj(path_or_file, mode='r'): if isinstance(path_or_file, basestring): - return open(path_or_file, mode) + try: + return open(path_or_file, mode) + except: + return closing(StringIO()) else: return closing(path_or_file) diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py index fbfc9a55..7eecc01a 100644 --- a/tests/utilities_tests.py +++ b/tests/utilities_tests.py @@ -23,6 +23,10 @@ class GrepTest(unittest.TestCase): matches = grep(".*unittest$", open(__file__.replace(".pyc", ".py"))) self.assertEquals(matches, ['import unittest\n']) + def test_grep_multiple_files(self): + matches = grep(".*unittest$", __file__.replace(".pyc", ".py"), "does_not_exist.txt") + self.assertEquals(matches, ['import unittest\n']) + class DirTreeTest(unittest.TestCase): |