diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2014-06-02 14:51:16 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2014-06-02 14:51:16 +0100 |
commit | 5447facd2edd3b3e5f1d3ad736b411f8e6406077 (patch) | |
tree | ccd5b3e2af5444327f67663794ab7f0998aa922c | |
parent | 3dc05143f2aa8b23395aad1a24ec19c1d0ec5740 (diff) | |
download | sos-5447facd2edd3b3e5f1d3ad736b411f8e6406077.tar.gz |
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>
-rw-r--r-- | sos/plugins/__init__.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 8f5ca1b2..7eff4e65 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -216,6 +216,8 @@ 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.''' + 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: |