Ejemplo n.º 1
0
def key_del(request):
    if request.method == "POST":
        response = {"success": False, "error": ""}
        try:
            id = request.POST.get('id', None)
            if not id:
                response['error'] = '必要参数为空!'
                return HttpResponse(json.dumps(response), mimetype='application/json')

            submit = KeySubmit.objects(pk=id).first()

            if not submit:
                response['error'] = '未找到对象!'
                return HttpResponse(json.dumps(response), mimetype='application/json')

            submit.delete()
            response['success'] = True
            response['error'] = '执行成功!'
            return HttpResponse(json.dumps(response), mimetype='application/json')
        except Exception as e:
            response['error'] = '程序异常![%s]' % e.message
            logger.error(response['error'] + getTraceBack())
            return HttpResponse(json.dumps(response), mimetype='application/json')
    else:
        response = {"success": False, "error": "请使用http-post方法请求!"}
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 2
0
def key_del(request):
    if request.method == "POST":
        response = {"success": False, "error": ""}
        try:
            id = request.POST.get('id', None)
            if not id:
                response['error'] = '必要参数为空!'
                return HttpResponse(json.dumps(response),
                                    mimetype='application/json')

            submit = KeySubmit.objects(pk=id).first()

            if not submit:
                response['error'] = '未找到对象!'
                return HttpResponse(json.dumps(response),
                                    mimetype='application/json')

            submit.delete()
            response['success'] = True
            response['error'] = '执行成功!'
            return HttpResponse(json.dumps(response),
                                mimetype='application/json')
        except Exception as e:
            response['error'] = '程序异常![%s]' % e.message
            logger.error(response['error'] + getTraceBack())
            return HttpResponse(json.dumps(response),
                                mimetype='application/json')
    else:
        response = {"success": False, "error": "请使用http-post方法请求!"}
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 3
0
def key_list(request):
    if request.method == "GET":
        submits = KeySubmit.objects().order_by('branch', 'revision_start')
        return render_to_response("programBranch/key_submit_list.html", locals(), context_instance=RequestContext(request))
    else:
        response = {"success": False, "error": "请使用http-get方法请求!"}
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 4
0
def key_list(request):
    if request.method == "GET":
        submits = KeySubmit.objects().order_by('branch', 'revision_start')
        return render_to_response("programBranch/key_submit_list.html",
                                  locals(),
                                  context_instance=RequestContext(request))
    else:
        response = {"success": False, "error": "请使用http-get方法请求!"}
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 5
0
    def get_key_submit_by_revision(self, svn_url, revision_end, revision_start=-1):
        """
        根据旧SVN数据获取之后的关键更新
        :param svn_url:
        :param revision_end:
        :param revision_start:
        :return:
        """
        branch_info = self.get_branch_from_url(svn_url)
        # 获取最新的SVN版本号
        if revision_start == -1:
            revision_start = self.get_current_svn_revision(svn_url)

        # 查询在此区间的关键更新对象
        key_submits = KeySubmit.objects(Q(branch=branch_info) & (Q(revision_end__lte=revision_start) & Q(revision_end__gte=revision_end)) | (Q(revision_start__lte=revision_start) & Q(revision_start__gte=revision_end))).order_by('-revision_start')
        return key_submits
Ejemplo n.º 6
0
    def get_key_submit_by_revision(self,
                                   svn_url,
                                   revision_end,
                                   revision_start=-1):
        """
        根据旧SVN数据获取之后的关键更新
        :param svn_url:
        :param revision_end:
        :param revision_start:
        :return:
        """
        branch_info = self.get_branch_from_url(svn_url)
        # 获取最新的SVN版本号
        if revision_start == -1:
            revision_start = self.get_current_svn_revision(svn_url)

        # 查询在此区间的关键更新对象
        key_submits = KeySubmit.objects(
            Q(branch=branch_info) & (Q(revision_end__lte=revision_start)
                                     & Q(revision_end__gte=revision_end))
            | (Q(revision_start__lte=revision_start) & Q(
                revision_start__gte=revision_end))).order_by('-revision_start')
        return key_submits
Ejemplo n.º 7
0
def svn_list_read(request):
    response = {"success": False, "error": ""}

    if request.method == "GET":
        try:
            id = request.GET.get('id', None)
            revision_start_number = request.GET.get('revision_start', None)
            revision_end_number = request.GET.get('revision_end', None)
            limit = int(request.GET.get('limit', 30))

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

            branch = BranchInfo.objects(pk=id)

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

            branch = branch[0]

            # 读取最近50条更新
            svn_url = SvnUtils.get_svn_url(branch.programName, branch.branchTag)

            client = pysvn.Client()
            revision_start = pysvn.Revision(pysvn.opt_revision_kind.head)
            if revision_start_number:
                revision_start = pysvn.Revision(pysvn.opt_revision_kind.number, int(revision_start_number))
                limit += 1

            revision_end = pysvn.Revision(pysvn.opt_revision_kind.number, 0 if not revision_end_number else revision_end_number)

            svn_logs = client.log(svn_url, revision_start=revision_start, revision_end=revision_end, limit=limit)

            if revision_start_number:
                # 过滤掉页面已有数据
                svn_logs = svn_logs[1:]

            svn_log_json = convert_svn_log_json(svn_logs)

            key_submit_dict = {}
            if svn_logs:
                svn_revision_start = svn_logs[0].data['revision'].number
                svn_revision_end = svn_logs[len(svn_logs) - 1].data['revision'].number

                # 查询已有关键提交,标记之
                key_submits = KeySubmit.objects(Q(branch=branch) & (Q(revision_end__lte=svn_revision_start) & Q(revision_end__gte=svn_revision_end)) | (Q(revision_start__lte=svn_revision_start) & Q(revision_start__gte=svn_revision_end))).order_by('-revision_start')
                for item in key_submits:
                    revision_start_item = item.revision_start
                    revision_end_item = item.revision_end
                    # 版本号开始在区间内
                    if svn_revision_start >= revision_start_item >= svn_revision_end:
                        result = {'type': ['start'], 'remark': item.remark, 'create_user': item.create_user.username, 'id': str(item.id), 'time': item.create_time.strftime('%Y-%m-%d %H:%M:%S')}
                        key_submit_dict[revision_start_item] = result
                    # 版本号结束在区间内
                    if svn_revision_start >= revision_end_item >= svn_revision_end:
                        result = {'type': ['end'], 'remark': item.remark, 'create_user': item.create_user.username, 'id': str(item.id), 'time': item.create_time.strftime('%Y-%m-%d %H:%M:%S')}
                        if revision_end_item in key_submit_dict:
                            key_submit_dict[revision_end_item]['type'].append('end')
                        else:
                            key_submit_dict[revision_end_item] = result

            response['data'] = svn_log_json
            response['key_submit'] = key_submit_dict
            response['success'] = True
            return HttpResponse(json.dumps(response), mimetype="application/json")
        except Exception as e:
            response["error"] = "程序异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response), mimetype="application/json")

    else:
        response['error'] = '请使用Http-GET方式请求!'
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 8
0
def key_create(request):
    if request.method == "GET":
        branchs = BranchInfo.objects().order_by('-programName', 'branchTag')

        program_list = []
        tag_dict = {}

        for branch in branchs:
            program_name = branch.programName
            if program_name in tag_dict:
                tag_dict[program_name].append({
                    'id': str(branch.id),
                    'tag': branch.branchTag
                })
            else:
                program_list.append(program_name)
                tag_dict[program_name] = [{'id': str(branch.id), 'tag': branch.branchTag}]

        program_list_json = json.dumps(program_list)
        tag_dict_json = json.dumps(tag_dict)
        return render_to_response("programBranch/key_submit_create.html", locals(), context_instance=RequestContext(request))
    elif request.method == 'POST':
        response = {"success": False, "error": ""}
        try:
            # 获取参数
            json_str = request.POST.get('json', None)

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

            json_obj = json.loads(json_str)

            remark = json_obj['remark']
            id = json_obj['id']
            revision_1 = int(json_obj['revision_1'])
            revision_2 = json_obj['revision_2']
            revision_2 = revision_1 if revision_2 is None else int(revision_2)

            branch = BranchInfo.objects(pk=id)

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

            branch = branch[0]

            # 验证是否重叠
            exists = KeySubmit.objects(branch=branch, revision_start__lte=revision_1, revision_end__gte=revision_2)

            if exists:
                response['error'] = '关键提交重叠!'
                return HttpResponse(json.dumps(response), mimetype="application/json")

            key_submit = KeySubmit()
            key_submit.branch = branch
            key_submit.revision_start = revision_1
            key_submit.revision_end = revision_2
            key_submit.remark = remark
            key_submit.create_time = datetime.datetime.now()
            key_submit.create_user = User.objects.get(pk=request.user.id)
            key_submit.save()

            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")
Ejemplo n.º 9
0
def svn_list_read(request):
    response = {"success": False, "error": ""}

    if request.method == "GET":
        try:
            id = request.GET.get('id', None)
            revision_start_number = request.GET.get('revision_start', None)
            revision_end_number = request.GET.get('revision_end', None)
            limit = int(request.GET.get('limit', 30))

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

            branch = BranchInfo.objects(pk=id)

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

            branch = branch[0]

            # 读取最近50条更新
            svn_url = SvnUtils.get_svn_url(branch.programName,
                                           branch.branchTag)

            client = pysvn.Client()
            revision_start = pysvn.Revision(pysvn.opt_revision_kind.head)
            if revision_start_number:
                revision_start = pysvn.Revision(pysvn.opt_revision_kind.number,
                                                int(revision_start_number))
                limit += 1

            revision_end = pysvn.Revision(
                pysvn.opt_revision_kind.number,
                0 if not revision_end_number else revision_end_number)

            svn_logs = client.log(svn_url,
                                  revision_start=revision_start,
                                  revision_end=revision_end,
                                  limit=limit)

            if revision_start_number:
                # 过滤掉页面已有数据
                svn_logs = svn_logs[1:]

            svn_log_json = convert_svn_log_json(svn_logs)

            key_submit_dict = {}
            if svn_logs:
                svn_revision_start = svn_logs[0].data['revision'].number
                svn_revision_end = svn_logs[len(svn_logs) -
                                            1].data['revision'].number

                # 查询已有关键提交,标记之
                key_submits = KeySubmit.objects(
                    Q(branch=branch)
                    & (Q(revision_end__lte=svn_revision_start)
                       & Q(revision_end__gte=svn_revision_end))
                    | (Q(revision_start__lte=svn_revision_start)
                       & Q(revision_start__gte=svn_revision_end))).order_by(
                           '-revision_start')
                for item in key_submits:
                    revision_start_item = item.revision_start
                    revision_end_item = item.revision_end
                    # 版本号开始在区间内
                    if svn_revision_start >= revision_start_item >= svn_revision_end:
                        result = {
                            'type': ['start'],
                            'remark': item.remark,
                            'create_user': item.create_user.username,
                            'id': str(item.id),
                            'time':
                            item.create_time.strftime('%Y-%m-%d %H:%M:%S')
                        }
                        key_submit_dict[revision_start_item] = result
                    # 版本号结束在区间内
                    if svn_revision_start >= revision_end_item >= svn_revision_end:
                        result = {
                            'type': ['end'],
                            'remark': item.remark,
                            'create_user': item.create_user.username,
                            'id': str(item.id),
                            'time':
                            item.create_time.strftime('%Y-%m-%d %H:%M:%S')
                        }
                        if revision_end_item in key_submit_dict:
                            key_submit_dict[revision_end_item]['type'].append(
                                'end')
                        else:
                            key_submit_dict[revision_end_item] = result

            response['data'] = svn_log_json
            response['key_submit'] = key_submit_dict
            response['success'] = True
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")
        except Exception as e:
            response["error"] = "程序异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")

    else:
        response['error'] = '请使用Http-GET方式请求!'
        return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 10
0
def key_create(request):
    if request.method == "GET":
        branchs = BranchInfo.objects().order_by('-programName', 'branchTag')

        program_list = []
        tag_dict = {}

        for branch in branchs:
            program_name = branch.programName
            if program_name in tag_dict:
                tag_dict[program_name].append({
                    'id': str(branch.id),
                    'tag': branch.branchTag
                })
            else:
                program_list.append(program_name)
                tag_dict[program_name] = [{
                    'id': str(branch.id),
                    'tag': branch.branchTag
                }]

        program_list_json = json.dumps(program_list)
        tag_dict_json = json.dumps(tag_dict)
        return render_to_response("programBranch/key_submit_create.html",
                                  locals(),
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        response = {"success": False, "error": ""}
        try:
            # 获取参数
            json_str = request.POST.get('json', None)

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

            json_obj = json.loads(json_str)

            remark = json_obj['remark']
            id = json_obj['id']
            revision_1 = int(json_obj['revision_1'])
            revision_2 = json_obj['revision_2']
            revision_2 = revision_1 if revision_2 is None else int(revision_2)

            branch = BranchInfo.objects(pk=id)

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

            branch = branch[0]

            # 验证是否重叠
            exists = KeySubmit.objects(branch=branch,
                                       revision_start__lte=revision_1,
                                       revision_end__gte=revision_2)

            if exists:
                response['error'] = '关键提交重叠!'
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            key_submit = KeySubmit()
            key_submit.branch = branch
            key_submit.revision_start = revision_1
            key_submit.revision_end = revision_2
            key_submit.remark = remark
            key_submit.create_time = datetime.datetime.now()
            key_submit.create_user = User.objects.get(pk=request.user.id)
            key_submit.save()

            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")