File tree Expand file tree Collapse file tree 4 files changed +70
-0
lines changed
tests/unit/plugins/filter Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
1212- Add a "file" parameter to "path" module
1313- Add a "find" module
14+ - Add an "exclusify" filter
1415
1516## [ 1.1.0] - 2024-09-13
1617
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+
4+ def exclusify (value , against ):
5+ paths = value
6+ value_paths = {path ['path' ] for path in value }
7+
8+ for path in against :
9+ if path ['path' ] not in value_paths :
10+ path ['state' ] = 'absent'
11+ paths .append (path )
12+
13+ return paths
14+
15+
16+ class FilterModule (object ):
17+ ''' Manala path exclusify jinja2 filters '''
18+
19+ def filters (self ):
20+ return {
21+ "exclusify" : exclusify ,
22+ }
Original file line number Diff line number Diff line change 1+ ---
2+
3+ DOCUMENTATION :
4+ name : exclusify
5+ author :
6+ - Manala (@manala)
7+ short_description : Ensure exclusivity against a list of path, by marking the extras as absent
8+ description :
9+ - Ensure exclusivity against a list of path, by marking the extras as absent
10+ positional : _input,against
11+ options :
12+ _input :
13+ description : A list of paths.
14+ type : list
15+ elements : object
16+ required : true
17+ against :
18+ description : A list of paths.
19+ type : list
20+ elements : str
21+ required : true
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import unittest
4+ from plugins .filter .exclusify import exclusify
5+
6+
7+ class TestExclusify (unittest .TestCase ):
8+
9+ def test_exclusify (self ):
10+ self .assertEqual (
11+ [
12+ {"path" : "foo" },
13+ {"path" : "bar" },
14+ {'path' : 'baz' , 'state' : 'absent' },
15+ ],
16+ exclusify (
17+ [
18+ {"path" : "foo" },
19+ {"path" : "bar" },
20+ ],
21+ [
22+ {"path" : "bar" },
23+ {"path" : "baz" },
24+ ],
25+ )
26+ )
You can’t perform that action at this time.
0 commit comments