diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2019-03-22 11:54:39 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-03-22 18:31:09 +0000 |
commit | 01c7af02a986252a6b0a461090d09211fc4bba8a (patch) | |
tree | e2b556a8934c8de82c3ccdd140cdcdb270e0bef4 | |
parent | 2edf2bcde427b3c987e798d2589e768cb4c1830e (diff) | |
download | sos-01c7af02a986252a6b0a461090d09211fc4bba8a.tar.gz |
[Plugin] accept predicates in Plugin.add_string_as_file()
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index cfb98325..dfad221e 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -935,14 +935,22 @@ class Plugin(object): return outfn - def add_string_as_file(self, content, filename): + def add_string_as_file(self, content, filename, pred=None): """Add a string to the archive as a file named `filename`""" + + # Generate summary string for logging + summary = content.splitlines()[0] + if not isinstance(summary, six.string_types): + summary = content.decode('utf8', 'ignore') + + pred = self.get_predicate(pred=pred) + if pred is not None and not pred: + self._log_info("skipped string ...'%s' due to predicate (%s)" % + (summary, pred)) + return + self.copy_strings.append((content, filename)) - if content: - content = content.splitlines()[0] - if not isinstance(content, six.string_types): - content = content.decode('utf8', 'ignore') - self._log_debug("added string ...'%s' as '%s'" % (content, filename)) + self._log_debug("added string ...'%s' as '%s'" % (summary, filename)) def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, timeout=300, stderr=True, |