| 17 | |
| 18 | |
| 19 | class Group: |
| 20 | GROUP_DATA_DIR = "/www/server/panel/data/java_group" |
| 21 | GROUP_TMP_DIR = "/var/tmp/springboot/group" |
| 22 | |
| 23 | def __init__(self, group_id: Optional[str] = None, group_data: Optional[dict] = None): |
| 24 | self.group_id = group_id |
| 25 | if isinstance(group_data, dict): |
| 26 | self.config: Optional[Dict[str, Union[str, List]]] = group_data |
| 27 | else: |
| 28 | self.config = self.load_group_data_by_id() |
| 29 | |
| 30 | if not os.path.exists(self.GROUP_DATA_DIR): |
| 31 | os.makedirs(self.GROUP_DATA_DIR, 0o600) |
| 32 | |
| 33 | if not os.path.exists(self.GROUP_TMP_DIR): |
| 34 | os.makedirs(self.GROUP_TMP_DIR) |
| 35 | |
| 36 | self.running_data = { |
| 37 | "length": 0, # 已完成的数量 |
| 38 | "remaining": 0, # 未完成的数量 |
| 39 | "executing": 0, # 正在执行的数量 |
| 40 | "projects": [], # 项目操作详情 |
| 41 | "msg": "", # 信息 |
| 42 | "status": True, |
| 43 | } |
| 44 | |
| 45 | # 如果有配置文件,则表示可以执行 |
| 46 | def can_running(self) -> bool: |
| 47 | return isinstance(self.config, dict) |
| 48 | |
| 49 | @staticmethod |
| 50 | def new_group_id() -> str: |
| 51 | from uuid import uuid4 |
| 52 | return uuid4().hex[::2] |
| 53 | |
| 54 | # 从配置文件中加载数据 |
| 55 | def load_group_data_by_id(self) -> Optional[dict]: |
| 56 | config_file = "{}/{}.json".format(self.GROUP_DATA_DIR, self.group_id) |
| 57 | try: |
| 58 | data = json.loads(public.readFile(config_file)) |
| 59 | except: |
| 60 | return None |
| 61 | if isinstance(data, dict): |
| 62 | return data |
| 63 | else: |
| 64 | return None |
| 65 | |
| 66 | def save_group_data(self): |
| 67 | if self.config: |
| 68 | config_file = "{}/{}.json".format(self.GROUP_DATA_DIR, self.group_id) |
| 69 | public.writeFile(config_file, json.dumps(self.config)) |
| 70 | |
| 71 | # 更新旧版数据 |
| 72 | @classmethod |
| 73 | def update_group_data(cls) -> None: |
| 74 | json_file = "/www/server/panel/class/projectModel/java_project_groups.json" |
| 75 | if not os.path.isfile(json_file): |
| 76 | return |
no outgoing calls
no test coverage detected