def add(request): "增加一个task" getinfo=request.GET postinfo=request.POST if getinfo.has_key("data"): datatype=getinfo.get("data") if datatype=="table": u"表格数据填充" pageindex=getinfo.get("page") pageindex=int(pageindex) rowsnum=getinfo.get("rows") rowsnum=int(rowsnum) _task=Task.objects.all().order_by("-tid") buff={} task_pageobj=Paginator(_task,rowsnum) buff["records"]=_task.count() buff["total"]=task_pageobj.num_pages try: task_list=task_pageobj.page(pageindex) except: task_list=task_pageobj.page(task_pageobj.num_pages) add_fail_count_to_tasklist(task_list) add_run_status_to_tasklist(task_list) buff["page"]=task_list.number buff["rows"]=[{"cell":[i.tid,i.name,i.get_status(),[i.running,i.count],i.project,i.app,i.get_info() ,i.owner ,i.ip]} for i in task_list] elif datatype=="add": u"增加一个Task" ip=postinfo.get("ip") name=postinfo.get("name") svnpath=postinfo.get("url").strip() version=postinfo.get("version") svnuser=postinfo.get("svnuser") svnpasswd=postinfo.get("svnpasswd") info=postinfo.get("fn") args="" filename=postinfo.get("filename") buff={} valid_result= valid_input(ip,name,svnpath,version,svnuser,svnpasswd,info,args,filename) if valid_result!=True: buff["status"],buff["message"]=valid_result else: if version=="*": versioninfo=get_svn_top_version(svnurl=svnpath,svnuser=svnuser,svnpasswd=svnpasswd) if versioninfo[0]==False: buff["status"],buff["message"]=versioninfo else: version=versioninfo[1] if buff=={}: serve=get_task_serve() try: result=serve.adddaemon(name,svnpath,str(version),svnuser,svnpasswd,info,request.user.username,args,filename) if True == result: buff["status"],buff["message"]= True,u"创建成功!" else: buff["status"],buff["message"]=False,u"创建失败!" except Exception as e: buff["status"],buff["message"]=False,str(e) return HttpResponse(json.dumps(buff,ensure_ascii=False),mimetype="application/javascript") cronserve=CronServe.objects.all().values() return render_to_response("add_task.html",locals(),context_instance=RequestContext(request))
def modifycron(request): "更改cron信息" getinfo = request.GET postinfo = request.POST tid = getinfo.get("tid") _ip = postinfo.get("ip") name = postinfo.get("name") rule = postinfo.get("rule") svnpath = postinfo.get("url").strip() version = postinfo.get("version") svnuser = postinfo.get("svnuser") svnpasswd = postinfo.get("svnpasswd") info = postinfo.get("fn") args = "" filename = postinfo.get("filename") serve = get_cron_serve() buff = {} try: task = Task.objects.get(pk=int(tid)) except: buff["status"] = False buff["message"] = "Error!无效tid!" else: ip = task.ip if ip != _ip: buff["status"] = False buff["message"] = "不允许修改IP!" elif name != task.name: buff["status"] = False buff["message"] = "不允许修改计划任务名!" else: valid_result = valid_input(ip, name, rule, svnpath, version, svnuser, svnpasswd, info, args, filename) if valid_result != True: buff["status"], buff["message"] = valid_result else: if version == "*": versioninfo = get_svn_top_version(svnpath, svnuser, svnpasswd) if versioninfo[0] == False: buff["status"], buff["message"] = versioninfo else: version = versioninfo[1] if buff == {}: result = serve.modifycron(tid, name, svnpath, str(version), svnuser, svnpasswd, rule, info, request.user.username, args, filename) if result != True: buff["status"], buff["message"] = result else: buff["status"] = True buff["message"] = "Success!" return HttpResponse(json.dumps(buff, ensure_ascii=False, indent=True), mimetype="application/javascript")
def modifytask(request): "更改一个task" from utils import generate_dict getinfo=request.GET postinfo=request.POST tid=getinfo.get("tid") _ip=postinfo.get("ip") ip_list=postinfo.getlist("ip") name=postinfo.get("name") svnpath=postinfo.get("url").strip() version=postinfo.get("version") svnuser=postinfo.get("svnuser") svnpasswd=postinfo.get("svnpasswd") info=postinfo.get("fn") _type=postinfo.get("type") args="" filename=postinfo.get("filename") __info=valid_tid(request) if __info==False: buff=generate_dict(False,"此task非法!") else: task=__info[1] ip=task.ip if _ip!=ip: buff=generate_dict(False,"不允许修改IP!") elif name!=task.name: buff=generate_dict(False,"不允许修改后台任务名!") elif len(ip_list)>1: buff=generate_dict(False,"不可选择多台主机!") else: result=valid_input(ip,name,svnpath,version,svnuser,svnpasswd,info,args,filename) if result!=True: buff=generate_dict(*result) else: if version=="*": versioninfo=get_svn_top_version(svnpath,svnuser,svnpasswd) if versioninfo[0]==False: buff=generate_dict(versioninfo[0],versioninfo[1]) else: version=versioninfo[1] if not locals().has_key("buff"): result= run_serve_fun("modifydaemon",task.tid,name,svnpath,str(version),svnuser,svnpasswd,info,args,filename) if result==True: buff=generate_dict(True,"Success!") else: buff=generate_dict(*result) return HttpResponse(json.dumps(buff,ensure_ascii=False,indent=True),mimetype="application/javascript")
def add(request): "add cron" getinfo = request.GET postinfo = request.POST print getinfo print postinfo if getinfo.has_key("data"): "json data " datatype = getinfo.get("data") if datatype == "table": "表格数据填充" pageindex = getinfo.get("page") pageindex = int(pageindex) rowsnum = getinfo.get("rows") rowsnum = int(rowsnum) task_queryset = Task.objects.all().order_by("-tid") buff = {} #buff["page"]=pageindex task_pagiobj = Paginator(task_queryset, rowsnum) buff["records"] = task_pagiobj.count buff["total"] = task_pagiobj.num_pages try: task_list = task_pagiobj.page(pageindex) except: task_list = task_pagiobj.page(task_pagiobj.num_pages) buff["page"] = task_list.number buff["rows"] = [{ "cell": [ i.tid, i.name, i.get_status(), i.rule, i.project, i.app, i.get_info(), i.get_owner_and_type(), i.ip ] } for i in task_list] elif datatype == "add": "增加计划任务" ip = postinfo.get("ip") name = postinfo.get("name") rule = postinfo.get("rule") svnpath = postinfo.get("url").strip() version = postinfo.get("version") svnuser = postinfo.get("svnuser") svnpasswd = postinfo.get("svnpasswd") info = postinfo.get("fn") _type = postinfo.get("type") args = "" filename = postinfo.get("filename") buff = {} valie_result = valid_input(ip, name, rule, svnpath, version, svnuser, svnpasswd, info, args, filename) if valie_result != True: buff["status"], buff["message"] = valie_result else: if version == "*": versioninfo = get_svn_top_version(svnurl=svnpath, svnuser=svnuser, svnpasswd=svnpasswd) if versioninfo[0] == False: buff["status"], buff["message"] = versioninfo else: version = versioninfo[1] if buff == {}: server = get_cron_serve() result = server.addcron(name, svnpath, str(version), svnuser, svnpasswd, rule, info, request.user.username, args, filename) if result != True: buff["status"], buff["message"] = result else: buff["status"] = True buff["message"] = "Success!" return HttpResponse(json.dumps(buff, ensure_ascii=False), mimetype="application/javascript") else: return render_to_response("add.html", locals(), context_instance=RequestContext(request))