19 lines
461 B
Python
19 lines
461 B
Python
#!/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
|