MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / Script

Class Script

mod/project/node/dbutil/executor.py:20–68  ·  view source on GitHub ↗

对应scripts表

Source from the content-addressed store, hash-verified

18
19@dataclass
20class Script:
21 """对应scripts表"""
22 name: str
23 script_type: str
24 content: str
25 id: Optional[int] = None
26 description: Optional[str] = None
27 group_id: int = 0
28 created_at: Optional[datetime] = None
29 updated_at: Optional[datetime] = None
30
31 @staticmethod
32 def check(data: Dict[str, Any]) -> str:
33 if "script_type" not in data or not data["script_type"]:
34 return "脚本类型不能为空"
35 if not data["script_type"] in ["python", "shell"]:
36 return "脚本类型错误, 请选择python或shell"
37 if "content" not in data or not data["content"]:
38 return "脚本内容不能为空"
39 if "name" not in data or not data["name"]:
40 return "脚本名称不能为空"
41 return ""
42
43 @classmethod
44 def from_dict(cls, data: Dict[str, Any]) -> 'Script':
45 """从字典创建Script实例"""
46 return cls(
47 id=int(data['id']) if data.get('id', None) else None,
48 name=str(data['name']),
49 script_type=str(data['script_type']),
50 content=str(data['content']),
51 description=str(data['description']) if data.get('description', None) else None,
52 group_id=int(data['group_id']) if data.get('group_id', None) else 0,
53 created_at=datetime.fromisoformat(data['created_at']) if data.get('created_at', None) else None,
54 updated_at=datetime.fromisoformat(data['updated_at']) if data.get('updated_at', None) else None
55 )
56
57 def to_dict(self) -> Dict[str, Any]:
58 """转换为字典格式"""
59 return {
60 'id': self.id,
61 'name': self.name,
62 'script_type': self.script_type,
63 'content': self.content,
64 'description': self.description,
65 'group_id': self.group_id,
66 'created_at': self.created_at.isoformat() if self.created_at else None,
67 'updated_at': self.updated_at.isoformat() if self.updated_at else None
68 }
69
70
71@dataclass

Callers 1

create_taskMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected