-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new Prepper to handle keyword preparation. This is slightly inefficient since we will only realistically need this once, but baking it into the archive loop does not pose any other problems, and it would be more fragile to break out a special flow just for keywords. Signed-off-by: Jake Hunsaker <[email protected]>
- Loading branch information
1 parent
09c36b6
commit ce5d4f5
Showing
3 changed files
with
39 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2023 Red Hat, Inc. Jake Hunsaker <[email protected]> | ||
|
||
# This file is part of the sos project: https://github.com/sosreport/sos | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# version 2 of the GNU General Public License. | ||
# | ||
# See the LICENSE file in the source distribution for further information. | ||
|
||
import os | ||
|
||
from sos.cleaner.preppers import SoSPrepper | ||
|
||
|
||
class KeywordPrepper(SoSPrepper): | ||
""" | ||
Prepper to handle keywords passed to cleaner via either the `--keywords` | ||
or `--keyword-file` options. | ||
""" | ||
|
||
name = 'keyword' | ||
|
||
def _get_items_for_keyword(self, archive): | ||
items = [] | ||
for kw in self.opts.keywords: | ||
items.append(kw) | ||
if self.opts.keyword_file and os.path.exists(self.opts.keyword_file): | ||
with open(self.opts.keyword_file, 'r') as kwf: | ||
items.extend(kwf.read().splitlines()) | ||
|
||
for item in items: | ||
self.regex_items['keyword'].add(item) | ||
|
||
return items | ||
|
||
# vim: set et ts=4 sw=4 : |