(self, id, task_type, task_shell, other='')
| 169 | # 执行任务 |
| 170 | # task_type 0.执行shell 1.下载文件 2.解压文件 3.压缩文件 |
| 171 | def execute_task(self, id, task_type, task_shell, other=''): |
| 172 | if not os.path.exists(self.__task_path): |
| 173 | os.makedirs(self.__task_path, 384) |
| 174 | log_file = self.__task_path + str(id) + '.log' |
| 175 | |
| 176 | # 标记状态执行时间 |
| 177 | self.modify_task(id, 'status', -1) |
| 178 | self.modify_task(id, 'exectime', int(time.time())) |
| 179 | task_type = int(task_type) |
| 180 | # 开始执行 |
| 181 | if task_type == 0: # 执行命令 |
| 182 | public.ExecShell(task_shell + ' &> ' + log_file) |
| 183 | elif task_type == 1: # 下载文件 |
| 184 | if os.path.exists(self.down_log_total_file): |
| 185 | os.remove(self.down_log_total_file) |
| 186 | if not os.path.exists(os.path.dirname(other)): |
| 187 | os.makedirs(os.path.dirname(other)) |
| 188 | |
| 189 | public.ExecShell("wget -O '{}' '{}' --no-check-certificate -T 30 -t 5 -d &> {}".format(other, task_shell, log_file)) |
| 190 | if os.path.exists(log_file): |
| 191 | os.remove(log_file) |
| 192 | elif task_type == 2: # 解压文件 |
| 193 | zip_info = json.loads(other) |
| 194 | self._unzip(task_shell, zip_info['dfile'], |
| 195 | zip_info['password'], log_file, zip_info.get('power'), zip_info.get('user')) |
| 196 | elif task_type == 3: # 压缩文件 |
| 197 | zip_info = json.loads(other) |
| 198 | if not 'z_type' in zip_info: |
| 199 | zip_info['z_type'] = 'tar.gz' |
| 200 | print(self._zip( |
| 201 | task_shell, zip_info['sfile'], zip_info['dfile'], log_file, zip_info['z_type'],zip_info['volume_size'],zip_info['save_path'])) |
| 202 | elif task_type == 4: # 备份数据库 |
| 203 | self.backup_database(task_shell, log_file) |
| 204 | elif task_type == 5: # 导入数据库 |
| 205 | self.input_database(task_shell, other, log_file) |
| 206 | elif task_type == 6: # 备份网站 |
| 207 | self.backup_site(task_shell, log_file) |
| 208 | elif task_type == 7: # 恢复网站 |
| 209 | pass |
| 210 | elif task_type == 8: # 复制文件 |
| 211 | _info = json.loads(other) |
| 212 | public.ExecShell("cp -rv {} {} &> {}".format(_info['sfile'], _info['dfile'], log_file)) |
| 213 | elif task_type == 9: # 清空回收站 |
| 214 | _info = json.loads(other) |
| 215 | self.Close_Recycle_bin_new(_info["ctype"], _info["recycle_bin_list"], log_file) |
| 216 | elif task_type == 10: # 彻底删除文件 |
| 217 | _info = json.loads(other) |
| 218 | self.Batch_Del_Recycle_bin(_info["filenames"], log_file) |
| 219 | |
| 220 | # 标记状态与结束时间 |
| 221 | self.modify_task(id, 'status', 1) |
| 222 | self.modify_task(id, 'endtime', int(time.time())) |
| 223 | |
| 224 | def Batch_Del_Recycle_bin(self, filenames, log_file): |
| 225 | import shutil |
no test coverage detected