[master][WIP] Additions to utils.data: get_type(), glob_list(), list_rm_match(), replace_list_element(), updated_dict()#64703
Open
gluf-technik wants to merge 8 commits intosaltstack:masterfrom
Open
Conversation
Takes a list `orig` and inserts the elements of `updates_list` anyplace where an element equal `placeholder` has been. In list ['a', 'bx', 'c'] placeholder 'bx' would be replaced with the elements of ['b1', 'b2', 'b3'] resulting in list ['a', 'b1', 'b2', 'b3', 'c']. TODO: Update docs
Uses fnmatch for "globbing" elements of a list: The globbing the list [eth0, eth2, lo] with pattern 'eth*' results in [eth0, eth2] Same function as used in Salt's match.glob. https://docs.python.org/3/library/fnmatch.html TODO: - Update docs - Add `jinja_filter("glob_list")`?
Returns a list with those elements of the
argument `listing` which __do not__ match
the regular expression `rgx`.
TODO:
- Update docs
- Add `jinja_filter("list_rm_match")`?
Very useful for debugging templates.
TODO:
- Update docs
- Add `jinja_filter("get_type")`
AFAIK it's not possible in Jinja to get a new, updated/merged
dictionary, just using `{% do ...%}` with `.update()` to update
one inplace.
TODO:
- Update docs
- Add `@jinja_filter("update")`?
Author
|
Just as I wanted to mention I'm trying to get things in alphabetical order (I guess the file was kinda "append only"?) I realized |
Sorry, wrong branch, event if get_chk_gh_release needs utils.data.glob_list() This reverts commit 113a230.
dwoz
requested changes
Dec 16, 2023
Contributor
dwoz
left a comment
There was a problem hiding this comment.
@gluf-technik This needs to be re-based, tests added, and a changelog entry.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds some functions to
salt/utils/data.pyget_type()to query a Python type inside a Jinja templateglob_list()to get only the elements of a list matching the globlist_rm_match()to get a news list without the elements matching a regexreplace_list_element()to turn[a, bx, c]into[a, b1, b2 ,b3, c]updated_dict()to get an update of a dict without modifying the original oneI think all five are results of trying to make Jinja do things it's not made for
and at lease some of them may even be suitable for becoming Jinja filters.
Pointers to other modules doing those things are welcome, too, so we don't
have to maintain custom modules until this PR gets merged, even if only
partially ; )
What issues does this PR fix or reference?
Fixes:
NoneMerge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes/NoPlease review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.