Sophie

Sophie

distrib > Fedora > 19 > i386 > by-pkgid > 2183d0e55a8d454b8164909066cf1904 > files > 63

sos-3.1-1.fc19.src.rpm

From ae3d6498965f7396a6fa7e2f10f799a354060c6f Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 2 Jun 2014 14:51:16 +0100
Subject: [PATCH 63/72] Make do_path_regex_sub() honour string regex arguments

The Plugin.do_path_regex_sub() method to apply regex substitutions
to paths matching a pattern documents that it accepts either a
compiled re object or a regular expression as a string:

    '''Apply a regexp substituation to a set of files archived by
    sos. The set of files to be substituted is generated by matching
    collected file pathnames against pathexp which may be a regular
    expression string or compiled re object. The portion of the file
    to be replaced is specified via regexp and the replacement string
    is passed in subst.'''

It lies. Attempting to pass a string for the 'pathexp' parameter
will result in:

    Traceback (most recent call last):
      File "/usr/sbin/sosreport", line 23, in <module>
        main(sys.argv[1:])
      File "/usr/lib/python2.6/site-packages/sos/sosreport.py", line 1229, in main
        sos.execute()
    AttributeError: 'str' object has no attribute 'match'

    > /usr/lib/python2.6/site-packages/sos/plugins/__init__.py(219)do_path_regex_sub()
    -> match = pathexp.match

Look to see if the object we are passed has a 'match()' method and
call re.compile on it if it does not.

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>

Conflicts:
	sos/plugins/__init__.py
---
 sos/plugins/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 88c909f..cf37d89 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -198,7 +198,9 @@ class Plugin(object):
         expression string or compiled re object. The portion of the file
         to be replaced is specified via regexp and the replacement string
         is passed in subst.'''
-	match = pathexp.match
+        if not hasattr(pathexp, "match"):
+            pathexp = re.compile(pathexp)
+        match = pathexp.match
         file_list = [f for f in self.copied_files if match(f['srcpath'])]
         for file in file_list:
             self.do_file_sub(file['srcpath'], regexp, subst)
-- 
1.9.3