paulbsd-salt/states/_modules/software.py

19 lines
461 B
Python
Raw Permalink Normal View History

2021-11-14 13:37:49 +01:00
#!/usr/bin/python3
import re
import os
def cleanup(name=None, path=None, version=None):
res = []
version = version.replace(".", "\.")
keep_pattern = f"^{name}-(?!{version}).*$"
regex = re.compile(keep_pattern)
for f in os.listdir(path):
if regex.match(f):
to_remove = f"{path}/{f}"
res.append(to_remove)
__salt__["file.remove"](to_remove)
if len(res) > 1:
return res
return None