From 17a52312dd3e21e5f894093b1f6654f42dbaca64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=2E=20Nam=C3=A8che?= Date: Wed, 4 Feb 2026 12:26:46 +0300 Subject: [PATCH] add filter listadddel --- seb4itik/byow/plugins/filter/listadddel.py | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 seb4itik/byow/plugins/filter/listadddel.py diff --git a/seb4itik/byow/plugins/filter/listadddel.py b/seb4itik/byow/plugins/filter/listadddel.py new file mode 100644 index 0000000..367ec62 --- /dev/null +++ b/seb4itik/byow/plugins/filter/listadddel.py @@ -0,0 +1,52 @@ +#!/usr/bin/python + + +DOCUMENTATION = r""" + name: listadddel + short_description: This filter add and remove items to/from a list. + version_added: "0.2.2" + author: Sébastien Namèche (@seb4itik) + description: + - If my_list is ["un", "deux", "trois"], then: + - {{ my_list | listadddel(["quatre", "cinq"], ["un"]) }} + - will produce: + - ["deux", "trois", "quatre", "cinq"] + options: + _input: + description: A list of strings. + type: list + elements: str + required: true + add: + description: A list of string to add to _input. + type: list + elements: str + default: [] + delete: + description: A list of string to remove from _input. + type: list + elements: str + default: [] + notes: + - delete is tronger than add. If the string is present in both delete and + add, it will not be in returned list. +""" + + +RETURN = r""" + _value: + type: list + elements: str + description: + - List of strings with new and removed elements. +""" + + +class FilterModule(object): + def filters(self): + return { + 'listadddel': self.listadddel + } + + def listadddel(self, l, add=[], delete=[]): + return [e for e in l+add if e not in delete]