Exemple #1
0
    def check_brach_info(self):
        # 获取portal所有分支对象
        branchs = BranchInfo.objects()

        svn_utils = SvnUtils()

        exist = 0
        unknown = 0
        not_exist = 0

        for item in branchs:
            svn_url = SvnUtils.get_svn_url(item.programName, item.branchTag)
            flag = None
            try:
                flag = svn_utils.svn_url_exists(svn_url)
            except Exception as e:
                logger.error(getTraceBack())
                logger.error('校验BranchInfo[id=%s][url=%s]异常![%s]' %
                             (str(item.id), svn_url, e.message))
            item.is_exist = flag
            item.save()

            if flag is True:
                exist += 1
            elif flag is False:
                not_exist += 1
            else:
                unknown += 1

        logger.info('校验BranchInfo对象成功!共计[%s]条!有效路径[%s]条!无效路径[%s]条!未知路径[%s]条!' %
                    (len(branchs), exist, not_exist, unknown))
Exemple #2
0
def get_portal_status(portal_pack):
    svn_utils = SvnUtils()
    svn_url = portal_pack.svn_url
    portal_is_old = False
    current_revision = svn_utils.get_current_svn_revision(svn_url)
    previous_revision = int(portal_pack.svn_version)
    if current_revision > previous_revision:
        portal_is_old = True
    machine_json = {'portal_svn_info': []}
    portal_json = {
        'svn_url': svn_url,
        'previous_revision': previous_revision,
        'current_revision': current_revision,
        'is_old': portal_is_old,
        'key_submits': []
    }
    portal_key_submits = svn_utils.get_key_submit_by_revision(
        svn_url, previous_revision, revision_start=current_revision)
    if portal_key_submits:
        for key_submit in portal_key_submits:
            d = {
                'start': key_submit.revision_start,
                'end': key_submit.revision_end,
                'remark': key_submit.remark
            }
            portal_json['key_submits'].append(d)
    machine_json['portal_svn_info'].append(portal_json)
    return machine_json['portal_svn_info'], portal_is_old, portal_key_submits
Exemple #3
0
def get_serve_status(svn_info):
    server_is_old = False
    if svn_info:
        svn_info = json.loads(svn_info)
        svn_utils = SvnUtils()
        machine_json = {'server_svn_info': []}
        for server_svn_url in svn_info:
            value = svn_info[server_svn_url]
            server_previous_revision = value[1]
            server_current_revision = svn_utils.get_current_svn_revision(
                server_svn_url)
            branch_is_old = False
            if server_current_revision > server_previous_revision:
                server_is_old = True
                branch_is_old = True
            server_json = {
                'server_svn_url': server_svn_url,
                'server_previous_revision': server_previous_revision,
                'server_current_revision': server_current_revision,
                'is_old': branch_is_old,
                'key_submits': []
            }

            server_key_submits = svn_utils.get_key_submit_by_revision(
                server_svn_url,
                server_previous_revision,
                revision_start=server_current_revision)
            for server_key_submit in server_key_submits:
                server_json['key_submits'].append({
                    'start':
                    server_key_submit.revision_start,
                    'end':
                    server_key_submit.revision_end,
                    'remark':
                    server_key_submit.remark
                })
            machine_json['server_svn_info'].append(server_json)

    return machine_json['server_svn_info'], server_is_old, server_key_submits
Exemple #4
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")