Esempio n. 1
0
def create(request):
    """
    创建分支
    :param request:
    :return:
    """
    if request.method == "GET":
        src_version = -1
        src_branch = "trunk"
        dst_branch = "tags/"
        customer_tag = request.GET.get("customerTag", None)
        if customer_tag is not None:
            dst_branch = "tags/" + customer_tag + "_" + datetime.datetime.now(
            ).strftime("%Y%m%d")
        branches = PROGRAM_LIST4SVN
        return render_to_response("programBranch/programBranch_create.html",
                                  locals(),
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        SRC_REVISION = request.POST.get("src_version", -1)
        SRC_BRANCH = request.POST.get("src_branch", None).strip()
        DST_BRANCH = request.POST.get("dst_branch", None).strip()
        # TODO 客户标记这个参数并没有用到
        CUSTOM_TAG = request.POST.get("customer_tag", None).strip()
        if (SRC_BRANCH is None) or (len(SRC_BRANCH) == 0):
            error = "源路径设置有误为空"
            logger.error(error)
            return render_to_response('item/temp.html',
                                      locals(),
                                      context_instance=RequestContext(request))
        if (DST_BRANCH is None) or (len(DST_BRANCH) == 0):
            error = "目标路径设置有误为空"
            logger.error(error)
            return render_to_response('item/temp.html',
                                      locals(),
                                      context_instance=RequestContext(request))
        branches = request.POST.getlist("svn_branches")
        client = pysvn.Client()
        for x in branches:
            localDir = getLocalDir(x)
            maker = BranchMaker(localDir, SRC_BRANCH, DST_BRANCH, SRC_REVISION)
            try:
                maker.main()
            except Exception as e:
                error = e.message
                logger.error(error)
                return render_to_response(
                    'item/temp.html',
                    locals(),
                    context_instance=RequestContext(request))
        return redirect("/programBranch/load/")
Esempio n. 2
0
def load(request):
    """
    版本列表
    :param request:
    :return:
    """
    client = pysvn.Client()
    logger.info("load svn")

    for program in ALL_SVN_LIST:
        dir = getLocalDir(program)
        url = client.info(dir).data['url']
        logger.info("program:[%s],url:[%s]" % (program, url))
        # trunk
        info = None
        try:
            info = BranchInfo.objects().get(programName=program,
                                            branchTag="trunk")
        except:
            pass
        if info is None:
            info = BranchInfo()
            info.programName = program
            info.branchTag = "trunk"
            info.createDate = "999999"
            info.save()

        branches = []
        branches.extend(getBranches(client, url, "branches"))
        try:
            branches.extend(getBranches(client, url, "tags"))
        except Exception as e:
            pass
        for x in branches:
            info = None
            try:
                info = BranchInfo.objects().get(programName=program,
                                                branchTag=x)
            except:
                pass
            if info is None:
                info = BranchInfo()
                info.programName = program
                info.branchTag = x
                customerTag = getCustomerTag(x)
                customer = Customer.objects(tag=customerTag)
                if len(customer) > 0:
                    info.customerTag = customerTag
                info.createDate = getCreateDate(x)
                info.save()
    return redirect("/programBranch/list/", locals())
Esempio n. 3
0
def load(request):
    """
    版本列表
    :param request:
    :return:
    """
    client = pysvn.Client()
    logger.info("load svn")

    for program in ALL_SVN_LIST:
        dir = getLocalDir(program)
        url = client.info(dir).data['url']
        logger.info("program:[%s],url:[%s]" % (program, url))
        # trunk
        info = None
        try:
            info = BranchInfo.objects().get(programName=program, branchTag="trunk")
        except:
            pass
        if info is None:
            info = BranchInfo()
            info.programName = program
            info.branchTag = "trunk"
            info.createDate = "999999"
            info.save()

        branches = []
        branches.extend(getBranches(client, url, "branches"))
        try:
            branches.extend(getBranches(client, url, "tags"))
        except Exception as e:
            pass
        for x in branches:
            info = None
            try:
                info = BranchInfo.objects().get(programName=program, branchTag=x)
            except:
                pass
            if info is None:
                info = BranchInfo()
                info.programName = program
                info.branchTag = x
                customerTag = getCustomerTag(x)
                customer = Customer.objects(tag=customerTag)
                if len(customer) > 0:
                    info.customerTag = customerTag
                info.createDate = getCreateDate(x)
                info.save()
    return redirect("/programBranch/list/", locals())
Esempio n. 4
0
def create(request):
    """
    创建分支
    :param request:
    :return:
    """
    if request.method == "GET":
        src_version = -1
        src_branch = "trunk"
        dst_branch = "tags/"
        customer_tag = request.GET.get("customerTag", None)
        if customer_tag is not None:
            dst_branch = "tags/" + customer_tag + "_" + datetime.datetime.now().strftime("%Y%m%d")
        branches = PROGRAM_LIST4SVN
        return render_to_response("programBranch/programBranch_create.html", locals(), context_instance=RequestContext(request))
    elif request.method == 'POST':
        SRC_REVISION = request.POST.get("src_version", -1)
        SRC_BRANCH = request.POST.get("src_branch", None).strip()
        DST_BRANCH = request.POST.get("dst_branch", None).strip()
        # TODO 客户标记这个参数并没有用到
        CUSTOM_TAG = request.POST.get("customer_tag", None).strip()
        if (SRC_BRANCH is None) or (len(SRC_BRANCH) == 0):
            error = "源路径设置有误为空"
            logger.error(error)
            return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
        if (DST_BRANCH is None) or (len(DST_BRANCH) == 0):
            error = "目标路径设置有误为空"
            logger.error(error)
            return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
        branches = request.POST.getlist("svn_branches")
        client = pysvn.Client()
        for x in branches:
            localDir = getLocalDir(x)
            maker = BranchMaker(localDir, SRC_BRANCH, DST_BRANCH, SRC_REVISION)
            try:
                maker.main()
            except Exception as e:
                error = e.message
                logger.error(error)
                return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
        return redirect("/programBranch/load/")
Esempio n. 5
0
def operate(request):
    """
    SVN相关操作
    :param request:
    :return:
    """
    response = {"success": False, "error": ""}

    if request.method == "POST":
        try:
            # 获取参数
            cmd = request.POST.get('cmd', None)
            id = request.POST.get('id', None)

            if not cmd or not id:
                response["error"] = "必要参数为空!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            branch = BranchInfo.objects(pk=id)

            if len(branch) == 0:
                response["error"] = "未找到对象!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            branch = branch[0]

            path = getLocalDir(branch.programName) + "/" + branch.branchTag

            # 直接删除URL,无须变更操作目录
            if cmd != 'delete':
                os.chdir(path)

            if cmd == 'update':
                p = Popen(["svn", "up"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                outStr, errorStr = p.communicate()
                if len(errorStr) > 0:
                    response["error"] = '更新失败![%s]' % errorStr
                    return HttpResponse(json.dumps(response), mimetype="application/json")

            elif cmd == 'clean':
                p = Popen(["make", "clean"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                p.wait()

            elif cmd == 'compile':
                p = Popen(["make", "-j8", "all"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                outStr, errorStr = p.communicate()
                if len(errorStr) > 0:
                    response["error"] = '编译失败![%s]' % errorStr
                    return HttpResponse(json.dumps(response), mimetype="application/json")
            elif cmd == 'delete':
                svn_url = SvnUtils.get_svn_url(branch.programName, branch.branchTag)
                logger.info('删除目录 : [%s]!' % svn_url)
                if SvnUtils().svn_url_exists(svn_url):
                    p = Popen(["svn", "delete", "-m", "%s delete %s" % (User.objects.get(pk=request.user.id).username, svn_url), svn_url], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                    outStr, errorStr = p.communicate()
                    if len(errorStr.strip()) > 0 and not str(errorStr).startswith('svn: E160013:'):
                        response["error"] = '删除失败![%s]' % errorStr
                        return HttpResponse(json.dumps(response, ensure_ascii=False), mimetype="application/json")
                branch.delete()
                response["id"] = id
            else:
                response["error"] = "限制操作!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            response["success"] = True
            response["error"] = "执行成功!"
            return HttpResponse(json.dumps(response), mimetype="application/json")
        except Exception, e:
            response["error"] = "系统异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response), mimetype="application/json")
Esempio n. 6
0
def operate(request):
    """
    SVN相关操作
    :param request:
    :return:
    """
    response = {"success": False, "error": ""}

    if request.method == "POST":
        try:
            # 获取参数
            cmd = request.POST.get('cmd', None)
            id = request.POST.get('id', None)

            if not cmd or not id:
                response["error"] = "必要参数为空!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            branch = BranchInfo.objects(pk=id)

            if len(branch) == 0:
                response["error"] = "未找到对象!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            branch = branch[0]

            path = getLocalDir(branch.programName) + "/" + branch.branchTag

            # 直接删除URL,无须变更操作目录
            if cmd != 'delete':
                os.chdir(path)

            if cmd == 'update':
                p = Popen(["svn", "up"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                outStr, errorStr = p.communicate()
                if len(errorStr) > 0:
                    response["error"] = '更新失败![%s]' % errorStr
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")

            elif cmd == 'clean':
                p = Popen(["make", "clean"],
                          stdin=PIPE,
                          stdout=PIPE,
                          stderr=PIPE)
                p.wait()

            elif cmd == 'compile':
                p = Popen(["make", "-j8", "all"],
                          stdin=PIPE,
                          stdout=PIPE,
                          stderr=PIPE)
                outStr, errorStr = p.communicate()
                if len(errorStr) > 0:
                    response["error"] = '编译失败![%s]' % errorStr
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")
            elif cmd == 'delete':
                svn_url = SvnUtils.get_svn_url(branch.programName,
                                               branch.branchTag)
                logger.info('删除目录 : [%s]!' % svn_url)
                if SvnUtils().svn_url_exists(svn_url):
                    p = Popen([
                        "svn", "delete", "-m",
                        "%s delete %s" %
                        (User.objects.get(pk=request.user.id).username,
                         svn_url), svn_url
                    ],
                              stdin=PIPE,
                              stdout=PIPE,
                              stderr=PIPE)
                    outStr, errorStr = p.communicate()
                    if len(errorStr.strip()) > 0 and not str(
                            errorStr).startswith('svn: E160013:'):
                        response["error"] = '删除失败![%s]' % errorStr
                        return HttpResponse(json.dumps(response,
                                                       ensure_ascii=False),
                                            mimetype="application/json")
                branch.delete()
                response["id"] = id
            else:
                response["error"] = "限制操作!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            response["success"] = True
            response["error"] = "执行成功!"
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")
        except Exception, e:
            response["error"] = "系统异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")