示例#1
0
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))
示例#2
0
def logsdetail(request):
    "查看运行日志的stdout stderr"
    getinfo=request.GET
    postinfo=request.POST
    rid=getinfo.get("rid")
    runlog=RunLog.objects.get(pk=int(rid))
    stdout=runlog.stdout
    stderr=runlog.stderror
    #return  HttpResponse(json.dumps({"stdout":stdout,"stderr":stderr},ensure_ascii=False,indent=True),mimetype="application/javascript")
    return  render_to_response("cron_run_log.html",locals(),context_instance=RequestContext(request))
示例#3
0
def logdetail(request):
    "运行记录的log"
    getinfo=request.GET
    postinfo=request.POST
    rid=getinfo.get("rid")
    #info=valid_tid(request)
    #if info==False:
    #    return  HttpResponse("Error!")
    #else:
    runlog=Runlog.objects.get(pk=int(rid))
    stdout=runlog.stdout
    stderr=runlog.stderror
    #return  HttpResponse(json.dumps({"stdout":stdout,"stderr":stderr},ensure_ascii=False,indent=True),mimetype="application/javascript")
    return  render_to_response("task_run_log.html",locals(),context_instance=RequestContext(request))
示例#4
0
def manage(request):
    "管理task"
    getinfo=request.GET
    postinfo=request.POST
    if getinfo.has_key("data"):
        datatype=getinfo.get("data")
        if datatype=="table":
            "表格数据填充"
            pageindex=getinfo.get("page")
            pageindex=int(pageindex)
            rowsnum=getinfo.get("rows")
            rowsnum=int(rowsnum)
            _task=  Task.objects.all()
            _task= _task.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.get_name(),i.get_status(),[i.running,i.count],"","",i.get_info() ,i.owner,i.ip]}  for i in task_list]
            return  HttpResponse(json.dumps(buff,ensure_ascii=False),mimetype="application/javascript")

    elif getinfo.has_key("ip"):
        ip=getinfo.get("ip")
        status=getinfo.get("status")
        info=getinfo.get("fn")
        owner=getinfo.get("owner")
        rows=getinfo.get("rows","15")
        page=getinfo.get("page","1")
        def handleparam(ip,status,info,owner):
            result=locals()
            if ip=='':
                del result["ip"]
            if owner=='' or owner==None:
                del result["owner"]
            try:
                int(status)
            except:
                del result["status"]
            if info=='':
                del result["info"]
            if result.has_key("info"):
                del  result["info"]
                result["info__icontains"]=info
            return  result
        args=handleparam(ip,status,info,owner)

        task_queryset=Task.objects.filter(**args)
        task_queryset=Task.objects.filter(**args)
        task_queryset= task_queryset.order_by("-tid")
        task_pagiobj=Paginator(task_queryset,int(rows))
        buff={}
        buff["records"]=task_queryset.count()
        buff["total"]=task_pagiobj.num_pages
        try:
            task_list=task_pagiobj.page(int(page))
        except:
            task_list=task_pagiobj.page(1)
        buff["page"]=task_list.number
        add_fail_count_to_tasklist(task_list)
        add_run_status_to_tasklist(task_list)
        buff["rows"]=[{"cell":[i.tid,i.get_name(),i.get_status(), [i.running, i.count],"","",i.get_info(),i.owner ,i.ip]} for  i in task_list]
        return  HttpResponse(json.dumps(buff,ensure_ascii=False),mimetype="application/javascript")


    cronserve=CronServe.objects.all().order_by("ip")
    userinfo=User.objects.all().values("username")
    return  render_to_response("manage_task.html",locals(),context_instance=RequestContext(request))
示例#5
0
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))
示例#6
0
def password_changed_ok(request):
    return render_to_response("iddacultura/password_changed_ok.html",
                              context_instance=RequestContext(request))