def delete_work(request): """ :param request: Django request对象 :return: 返回删除或失败的状态到前台 """ if request.method == 'POST': id_list = request.POST.getlist('ids') ids = id_list[0].split(',') for id in ids: WorkInfo.objects.filter(id=id).delete() loginfo = WorkLog.objects.filter(work_id=id) if (loginfo): loginfo.delete() log.info(get_user_ip(request) + "删除作业连带日志公成功,作业ID为:" + str(id)) log.info(get_user_ip(request) + "删除作业成功,作业ID为:" + str(id)) if get_time(id=str(id)) is not None: vv = get_time(id=str(id)) rem_time(id=str(id)) log.info( get_user_ip(request) + "删除原有定时成功!,定时ID为:" + str(id) + ',时间为:' + str(vv.trigger)) result = 'success' else: result = 'failed' return HttpResponse(result)
def updateWorkinfo(request, workinfo): result = 'failed' wid = workinfo['id'] workinfoUpdated = WorkInfo.objects.filter(id=wid).update(**workinfo) if workinfoUpdated is not None: result = 'success' log.info(get_user_ip(request) + "作业更新成功!,作业ID为:" + workinfo['id']) if workinfo['time_rule'] != '': # 删除定时 if get_time(id=workinfo['id']) is not None: vv = get_time(id=workinfo['id']) rem_time(id=workinfo['id']) log.info( get_user_ip(request) + "删除原有定时成功!,定时ID为:" + workinfo['id'] + ',时间为:' + str(vv.trigger)) # 重新定时 add_time(run_work_time, args=(request, workinfo['id']), id=workinfo['id'], time=workinfo['time_rule']) log.info( get_user_ip(request) + "作业更新定时成功!,作业ID为:" + workinfo['id'] + ',定时规则为:' + workinfo['time_rule']) return result
def upload(request): log.info(get_user_ip(request) + "遍历本地公共目录,获取zip文件") dir_o = PublicParameter.objects.get(confK='local_public_dir') path = dir_o.confV fs = os.listdir(path) list_files = [] for f1 in fs: tmp_path = os.path.join(path, f1) if not os.path.isdir(tmp_path): print('文件: %s' % tmp_path) list_files.append(tmp_path) log.info(get_user_ip(request) + '文件: %s' % tmp_path) else: print('文件夹:%s' % tmp_path) log.info(get_user_ip(request) + '文件夹:%s' % tmp_path) return sorted(list_files)
def stop_work(request): # 中断作业需要知道作业的id id = request.POST.get('work_id') # 同时这里使用的中断是将当前任务正在执行的脚本执行完毕,所以是否存在中断后无法立即处理的问题? WorkInfo.objects.filter(id=id).update(work_status=3) log.info(get_user_ip(request) + "作业中断成功,作业ID为:" + id) # 同时涉及批量中断,那就需要获取多个id, # 中断也就是远程的执行,只不过将执行取消掉而已 return HttpResponse('success')
def upload_zip(request): log.info(get_user_ip(request) + "页面上传zip文件的方法") if request.method == 'POST': # 可以获取上传文件的文件名 tool_file = request.FILES.get('file') # 指定临时文件写入路径 file_path = 'static/zips/' # 这里写入文件后一定要关闭,要不然下面会读取不到 f = open(os.path.join(file_path, tool_file.name), 'wb') for chunk in tool_file.chunks(chunk_size=1024): f.write(chunk) f.close() result = 'success' log.info(get_user_ip(request) + "zip文件上传success") else: result = 'failed' log.info(get_user_ip(request) + "zip文件上传failed") return HttpResponse(result)
def createOrUpdateWork(request): result = 'success' work = {} for key in request.POST: work[key] = request.POST.get(key) five_list = request.POST.get('value_list') file_package_names = request.POST.get('file_package_names') work['file_package_names'] = file_package_names.replace(' ', '') if work['id'] != '': result = updateWorkinfo(request, work) return HttpResponse(result) work.pop('id') value_list = ppp(work['province'], work['platform'], work['project'], five_list) work['value_list'] = value_list work_saved = WorkInfo.objects.create(**work) log.info(get_user_ip(request) + "作业创建成功!,作业ID为:" + str(work_saved.id)) # 添加定时 if work['time_rule'] != '': # 加入定时 add_time(run_work_time, args=(request, work_saved.id), id=work_saved.id, time=work['time_rule']) log.info( get_user_ip(request) + "作业创建定时成功!,作业ID为:" + str(work_saved.id) + ",定时规则为:" + work['time_rule']) if work_saved is None: result = 'failed' return HttpResponse(result)
def upload_mutifile(request): log.info((get_user_ip(request) + "进入上传方法")) files = request.FILES.getlist('fileList') x = getPublicParameterKeyword('work_param')[0]['confV'] file_path = '' for key, value in (json.loads(x)).items(): if key == 'local_public_dir': # 获取路径 file_path = value[0] directory = os.listdir(file_path) for file in files: # if str(file) in directory: # # print('文件已存在,是否要替换文件:' + str(file)) # return HttpResponse('exists') # 将上次文件写入路径 f = open(os.path.join(file_path, file.name), 'wb') for chunk in file.chunks(chunk_size=1024): f.write(chunk) f.close() return HttpResponse('success')
def mods(request): log.info(get_user_ip(request) + '进入模板模块') return render(request, 'mod/mods.html')
def scripts(request): log.info(get_user_ip(request) + '进入脚本模块') return render(request, 'script/scripts.html')
def userList(request): userList = service.getUsers(request) log.info(sshUtil.get_user_ip(request) + "进入用户模块!") return render(request, 'user/userList.html', {"users": userList})
def userGroupList(request): log.info(sshUtil.get_user_ip(request) + "进入用户组模块!") userGroupList = service.getUserGroupList(request) return render(request, 'userGroup/userGroupList.html', {"data": userGroupList})
def auth_logout(request): log.info(sshUtil.get_user_ip(request) + "登出系统!") logout(request) return redirect("/")
def auth_login(request): log.info(sshUtil.get_user_ip(request) + "登录系统!") return HttpResponse(service.auth_login(request))
def permissionList(request): result = service.permissionList(request) log.info(sshUtil.get_user_ip(request) + "进入权限模块!") return render(request, 'authority/authorityList.html', {"data": result})
def works(request): work_list = WorkInfo.objects.all().order_by('-id') log.info(get_user_ip(request) + '进入作业模块') return render(request, 'work/works.html', {'data': work_list})
def configs(request): log.info(get_user_ip(request) + '进入配置模块') result_list = getPublicParameterKeyword(keyword=PROJECT_TYPE) return render(request, 'config/configs.html', {"data": result_list})