jumpserver/apps/ops/ansible/cleaner.py
fit2bot 52922088a9
feat: 优化代码结构,receptor开关,修改为 tcp 通信 (#13078)
* feat: 优化代码结构,receptor开关,修改为 tcp 通信

* fix: 修改导包路径

* fix: 修复错别字

* fix: 修改导包路径

* perf: 优化代码

* fix: 修复任务不执行的问题

* perf: 优化配置项名称

* perf: 优化代码结构

* perf: 优化代码

---------

Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
2024-04-22 13:51:52 +08:00

39 lines
932 B
Python

import os
import shutil
from functools import wraps
from settings.api import settings
__all__ = ["WorkPostRunCleaner", "cleanup_post_run"]
class WorkPostRunCleaner:
@property
def clean_dir(self):
raise NotImplemented
def clean_post_run(self):
if settings.DEBUG_DEV:
return
if self.clean_dir and os.path.exists(self.clean_dir):
shutil.rmtree(self.clean_dir)
def cleanup_post_run(func):
def get_instance(*args):
if not len(args) > 0:
return
return args[0]
@wraps(func)
def wrapper(*args, **kwargs):
instance = get_instance(*args)
if not instance or not issubclass(type(instance), WorkPostRunCleaner):
raise NotImplementedError("you should extend 'WorkPostRunCleaner'")
try:
return func(*args, **kwargs)
finally:
instance.clean_post_run()
return wrapper