Esempio n. 1
0
def main(args):
    buildpatch = True
    buildreport = True
    rebuildrepo = True
    repoid = None
    if len(args) > 1:
        arg = args[1]
        if arg == 'patch':
            buildreport = False
            rebuildrepo = False
        elif arg == 'report':
            buildpatch = False
            rebuildrepo = False

    if len(args) > 2:
        repoid = int(args[2])

    for repo in GitRepo.objects.filter(status = True, build = True):
        if repoid != None and repoid != repo.id:
            continue

        patchcnt = Patch.objects.filter(tag__repo = repo, build = 0, mergered = 0, status = STATUS_NEW).count()
        reportcnt = Report.objects.filter(tag__repo = repo, build = 0, mergered = 0, status = STATUS_PATCHED).count()
        if (buildpatch == False or patchcnt == 0) and (buildreport == False or reportcnt == 0):
            continue

        logger = MyLogger()
        logs = ScanLog(reponame = repo.name, tagname = '-',
                       starttime = strftime("%Y-%m-%d %H:%M:%S", localtime()),
                       desc = 'Building, please wait...')
        logs.save()

        pcount = {'total': 0, 'pass': 0, 'fail': 0}
        rcount = {'total': 0, 'pass': 0, 'fail': 0}
        # prepare build env
        gitlog = ''
        if not os.path.exists(repo.builddir()):
            os.system("cd %s; git clone file://%s" % (os.path.dirname(repo.builddir()), repo.dirname()))
            if repo.name == 'linux-next.git':
                os.system("cd %s; cp %s/.git/refs/remotes/origin/stable .git/refs/remotes/stable" % (repo.builddir(), repo.dirname()))
            os.system("cd %s; make allmodconfig" % repo.builddir())
            rebuildrepo = True
        elif rebuildrepo == True:
            if repo.name == 'linux-next.git':
                if is_linux_next_update(repo):
                    os.system("cd %s; git reset --hard %s" % (repo.builddir(), get_linux_next_stable(repo)))
                    ret, tmplog = execute_shell_log("cd %s; git pull" % repo.builddir(), logger)
                    gitlog = tmplog
                    os.system("cd %s; cp %s/.git/refs/remotes/origin/stable .git/refs/remotes/stable" % (repo.builddir(), repo.dirname()))
                    os.system("cd %s; make allmodconfig" % repo.builddir())
                else:
                    gitlog = 'Already up-to-date.'
            else:
                os.system("cd %s; git reset --hard" % repo.builddir())
                ret, tmplog = execute_shell_log("cd %s; git pull" % repo.builddir(), logger)
                gitlog = tmplog

        #if rebuildrepo == True and gitlog.find('Already up-to-date.') == -1:
        #    execute_shell("cd %s; make" % repo.builddir(), logger)

        commit = commit_from_repo(repo)

        if buildpatch == True:
            for patch in Patch.objects.filter(tag__repo = repo, build = 0, mergered = 0, status = STATUS_NEW):
                buildlog = ''
    
                if patch.file.find('arch/') == 0 and patch.file.find('arch/x86') != 0:
                    patch.build = 3
                    patch.save()
                    continue

                pcount['total'] += 1
                fname = os.path.join(patch.dirname(), patch.filename())
                pdiff = open(fname, "w")
                try:
                    pdiff.write(patch.content)
                except:
                    pdiff.write(unicode.encode(patch.content, 'utf-8'))
                pdiff.close()
    
                print "build for patch %s...\n" % os.path.basename(fname)
                logger.logger.info("build for patch %s..." % os.path.basename(fname))
    
                execute_shell("cd %s; git reset --hard %s" % (repo.builddir(), commit), logger)
                if os.path.exists(os.path.join(repo.builddir(), '.git/rebase-apply')):
                    execute_shell("cd %s; rm -rf .git/rebase-apply" % repo.builddir())
    
                objfile = "%s.o" % patch.file[:-2]
                if patch.type.flags & TYPE_BUILD_SPARSE_CHECK:
                    if not os.path.isdir(os.path.join(repo.builddir(), patch.file)):
                        buildlog += '# make C=2 %s\n' % objfile
                        ret, log = execute_shell_log("cd %s; make C=2 %s" % (repo.builddir(), objfile), logger)
                        buildlog += log
                        buildlog += '\n'

                    dname = os.path.dirname(patch.file)
                    if len(dname.split(os.sep)) > 2:
                        buildlog += '# make C=2 M=%s\n' % dname
                        ret, log = execute_shell_log("cd %s; make C=2 M=%s" % (repo.builddir(), dname), logger)
                        buildlog += log
                        buildlog += '\n'

                ret, log = execute_shell_log("cd %s; git am %s" % (repo.builddir(), fname), logger)
                buildlog += '# git am %s\n' % os.path.basename(fname)
                buildlog += log
                if ret != 0:
                    pcount['fail'] += 1
                    patch.build = 2
                    patch.buildlog = buildlog
                    patch.save()
                    continue

                if patch.file.find('tools/') == 0:
                    dname = os.path.dirname(patch.file)
                    while len(dname) != 0 and not os.path.exists(os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# cd %s; make\n' % dname
                        ret, log = execute_shell_log("cd %s; make" % (os.path.join(repo.builddir(), dname)), logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            patch.build = 2
                            patch.buildlog = buildlog
                            patch.save()
                            continue
                    else:
                        buildlog += 'do not known how to build\n'
                    log += '\nLD [M] %s\n' % objfile

                if patch.file.find('include/') != 0 and patch.file.find('tools/') != 0:
                    dname = os.path.dirname(patch.file)
                    while len(dname) != 0 and not os.path.exists(os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# make M=%s\n' % dname
                        ret, log = execute_shell_log("cd %s; make M=%s" % (repo.builddir(), dname), logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            patch.build = 2
                            patch.buildlog = buildlog
                            patch.save()
                            continue
    
                output = log
                if is_c_file(patch.file) and is_module_build(patch.file, output) == False:
                    buildlog += '\n# make %s\n' % objfile
                    ret, log = execute_shell_log("cd %s; make %s" % (repo.builddir(), objfile), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        patch.build = 2
                        patch.buildlog = buildlog
                        patch.save()
                        if buildlog.find("Run 'make oldconfig' to update configuration.") != -1:
                            os.system("cd %s; make allmodconfig" % repo.builddir())
                        continue
                    output = log
                    if output.find(objfile) != -1:
                        log += '\nLD [M] %s\n' % objfile

                output = log
                if patch.file.find('include/') == 0 or is_module_build(patch.file, output) == False:
                    buildlog += '\n# make vmlinux\n'
                    ret, log = execute_shell_log("cd %s; make vmlinux" % (repo.builddir()), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        patch.build = 2
                        patch.buildlog = buildlog
                        patch.save()
                        if buildlog.find("Run 'make oldconfig' to update configuration.") != -1:
                            os.system("cd %s; make allmodconfig" % repo.builddir())
                        continue

                if patch.type.flags & TYPE_BUILD_SPARSE_CHECK:
                    if not os.path.isdir(os.path.join(repo.builddir(), patch.file)):
                        buildlog += '# make C=2 %s\n' % objfile
                        ret, log = execute_shell_log("cd %s; make C=2 %s" % (repo.builddir(), objfile), logger)
                        buildlog += log
                        buildlog += '\n'

                    dname = os.path.dirname(patch.file)
                    if len(dname.split(os.sep)) > 2:
                        buildlog += '# make C=2 M=%s\n' % dname
                        ret, log = execute_shell_log("cd %s; make C=2 M=%s" % (repo.builddir(), dname), logger)
                        buildlog += log
                        buildlog += '\n'

                pcount['pass'] += 1
                if buildlog.find(': warning: ') != -1:
                    patch.build = 4
                else:
                    patch.build = 1
                patch.buildlog = buildlog
                patch.save()

        if buildreport == True:
            for report in Report.objects.filter(tag__repo = repo, build = 0, mergered = 0, status = STATUS_PATCHED):
                buildlog = ''
    
                if report.file.find('arch/') == 0 and report.file.find('arch/x86') != 0:
                    report.build = 3
                    report.save()
                    continue

                rcount['total'] += 1
                fname = os.path.join(report.dirname(), report.filename())
                pdiff = open(fname, "w")
                try:
                    pdiff.write(report.content)
                except:
                    pdiff.write(unicode.encode(report.content, 'utf-8'))
                pdiff.close()

                print "build for report patch %s...\n" % os.path.basename(fname)
                logger.logger.info("build for report patch %s..." % os.path.basename(fname))
    
                execute_shell("cd %s; git reset --hard %s" % (repo.builddir(), commit), logger)
                if os.path.exists(os.path.join(repo.builddir(), '.git/rebase-apply')):
                    execute_shell("cd %s; rm -rf .git/rebase-apply" % repo.builddir())
    
                ret, log = execute_shell_log("cd %s; git am %s" % (repo.builddir(), fname), logger)
                buildlog += '# git am %s\n' % os.path.basename(fname)
                buildlog += log
                if ret != 0:
                    rcount['fail'] += 1
                    report.build = 2
                    report.buildlog = buildlog
                    report.save()
                    continue

                if report.file.find('tools/') == 0:
                    dname = os.path.dirname(report.file)
                    while len(dname) != 0 and not os.path.exists(os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# cd %s; make\n' % dname
                        ret, log = execute_shell_log("cd %s; make" % (os.path.join(repo.builddir(), dname)), logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            report.build = 2
                            report.buildlog = buildlog
                            report.save()
                            continue
                    else:
                        buildlog += 'do not known how to build\n'
                    log += '\nLD [M] %s\n' % objfile

                objfile = "%s.o" % report.file[:-2]
                if report.file.find('include/') != 0 and report.file.find('tools/') != 0:
                    dname = os.path.dirname(report.file)
                    while len(dname) != 0 and not os.path.exists(os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# make M=%s\n' % dname
                        ret, log = execute_shell_log("cd %s; make M=%s" % (repo.builddir(), dname), logger)
                        buildlog += log
                        if ret != 0:
                            rcount['fail'] += 1
                            report.build = 2
                            report.buildlog = buildlog
                            report.save()
                            continue

                output = log
                if is_c_file(report.file) and is_module_build(report.file, output) == False:
                    buildlog += '\n# make %s\n' % objfile
                    ret, log = execute_shell_log("cd %s; make %s" % (repo.builddir(), objfile), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        report.build = 2
                        report.buildlog = buildlog
                        report.save()
                        if buildlog.find("Run 'make oldconfig' to update configuration.") != -1:
                            os.system("cd %s; make allmodconfig" % repo.builddir())
                        continue
                    output = log
                    if output.find(objfile) != -1:
                        log += '\nLD [M] %s\n' % objfile

                output = log
                if report.file.find('include/') == 0 or is_module_build(report.file, output) == False:
                    buildlog += '\n# make vmlinux\n'
                    ret, log = execute_shell_log("cd %s; make vmlinux" % (repo.builddir()), logger)
                    buildlog += log
                    if ret != 0:
                        rcount['fail'] += 1
                        report.build = 2
                        report.buildlog = buildlog
                        report.save()
                        continue
    
                rcount['pass'] += 1
                if buildlog.find(': warning: ') != -1:
                    report.build = 4
                else:
                    report.build = 1
                report.buildlog = buildlog
                report.save()

        logs.desc = 'build patch: %d, pass: %d fail:%d, build report: %s, pass: %d, fail: %s' \
                    % (pcount['total'], pcount['pass'], pcount['fail'], rcount['total'], rcount['pass'], rcount['fail'])
        logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
        logs.logs = logger.getlog()
        logs.save()

        os.system("cd %s; git reset --hard %s" % (repo.builddir(), commit))
Esempio n. 2
0
def main(args):
    for patch in Patch.objects.filter(commit="", status=STATUS_ACCEPTED):
        if not os.path.exists(os.path.join(patch.tag.repo.dirname(), patch.file)):
            continue
        ptitle = re.sub("Subject: \[PATCH[^\]]*]", "", patch.title).strip()
        ptitle = re.sub("^.*:", "", ptitle).strip()
        if len(ptitle) > 2:
            ptitle = ptitle[1:]
        cmds = 'cd %s; git log --author="%s" --pretty="format:%%H|%%s" %s' % (
            patch.tag.repo.dirname(),
            patch.tag.repo.user,
            patch.file,
        )
        for line in execute_shell_full(cmds)[::-1]:
            if line.find("|") == -1:
                continue
            rtitle = line.split("|")[1]
            if line.upper().find(ptitle.upper()) == -1 and ptitle.upper().find(rtitle.upper()) == -1:
                continue
            commit = line.split("|")[0]
            if Patch.objects.filter(commit=commit).count() != 0:
                continue
            patch.commit = commit
            patch.save()
            break

    for report in Report.objects.filter(commit="", status=STATUS_ACCEPTED):
        if not os.path.exists(os.path.join(patch.tag.repo.dirname(), patch.file)):
            continue
        ptitle = re.sub("Subject: \[PATCH[^\]]*]", "", report.title).strip()
        ptitle = re.sub("^.*:", "", ptitle).strip()
        if len(ptitle) > 2:
            ptitle = ptitle[1:]
        cmds = 'cd %s; git log --author="%s" --pretty="format:%%H|%%s" %s' % (
            report.tag.repo.dirname(),
            report.tag.repo.user,
            report.file,
        )
        for line in execute_shell_full(cmds)[::-1]:
            if line.find(ptitle) == -1:
                continue
            commit = line.split("|")[0]
            if Report.objects.filter(commit=commit).count() != 0:
                continue
            report.commit = commit
            report.save()
            break

    stablerepo = None
    for repo in GitRepo.objects.filter(status=True):
        if stablerepo is None:
            stablerepo = repo
        git = GitTree(repo.name, repo.dirname(), repo.url, repo.commit, repo.stable)
        if git.is_linux_next() == True and git.get_commit() == git.get_stable():
            continue
        logger = MyLogger()
        logs = ScanLog(
            reponame=repo.name,
            tagname="-",
            starttime=strftime("%Y-%m-%d %H:%M:%S", localtime()),
            desc="Processing, please wait...",
        )
        logs.save()

        for tag in GitTag.objects.filter(repo=repo):
            ptotal = Patch.objects.filter(tag=tag, mergered=0).count()
            rtotal = Report.objects.filter(tag=tag, mergered=0).count()
            if ptotal != tag.total:
                tag.total = ptotal
                tag.save()
            if rtotal != tag.rptotal:
                tag.rptotal = rtotal
                tag.save()
            if tag.running is True:
                tag.running = False
                tag.save()

        pcount = {"total": 0, "removed": 0, "fixed": 0, "applied": 0, "stable": 0}
        for dot in patch_engine_list():
            test = dot(repo.dirname(), logger.logger, repo.builddir())
            for i in range(test.tokens()):
                rtype = None
                try:
                    rtype = Type.objects.filter(id=test.get_type())[0]
                except:
                    test.next_token()
                    continue

                if rtype.status == False:
                    test.next_token()
                    continue

                logger.info("Starting update type %d" % test.get_type())

                if repo.name == "linux-next.git":
                    patchs = Patch.objects.filter(Q(type=rtype), Q(status=STATUS_NEW) | Q(status=STATUS_SENT))
                else:
                    patchs = Patch.objects.filter(
                        Q(tag__repo=repo), Q(type=rtype), Q(status=STATUS_NEW) | Q(status=STATUS_SENT)
                    )

                for patch in patchs:
                    if not patch.mglist is None and len(patch.mglist) != 0:
                        continue
                    test.set_filename(patch.file)
                    pcount["total"] += 1
                    print "check for %s\n" % patch.filename()
                    if may_reject_cleanup(patch.file):
                        update_patch_status(patch, STATUS_REJECTED)
                        logger.logger.info("rejected patch %d" % patch.id)
                        continue

                    if not os.path.exists(test._get_file_path()):
                        update_patch_status(patch, STATUS_REMOVED)
                        pcount["removed"] += 1
                        logger.logger.info("removed patch %d" % patch.id)
                        continue

                    should_patch = test.should_patch()
                    if test.has_error():
                        continue
                    if should_patch == False:
                        if patch.status == STATUS_NEW:
                            if patch.mergered != 0:
                                mpatch = Patch.objects.filter(id=patch.mergered)
                                if len(mpatch) != 0:
                                    if mpatch[0].status == STATUS_SENT:
                                        update_patch_status(patch, STATUS_ACCEPTED)
                                        pcount["applied"] += 1
                                        logger.logger.info("applied patch %d" % patch.id)
                                    else:
                                        update_patch_status(patch, STATUS_FIXED)
                                        pcount["fixed"] += 1
                                        logger.logger.info("fixed patch %d" % patch.id)
                                else:
                                    update_patch_status(patch, STATUS_FIXED)
                                    pcount["fixed"] += 1
                                    logger.logger.info("fixed patch %d" % patch.id)
                            else:
                                update_patch_status(patch, STATUS_FIXED)
                                pcount["fixed"] += 1
                                logger.logger.info("fixed patch %d" % patch.id)
                        elif patch.status == STATUS_SENT:
                            update_patch_status(patch, STATUS_ACCEPTED)
                            pcount["applied"] += 1
                            logger.logger.info("applied patch %d" % patch.id)
                    elif repo.name == "linux-next.git" and patch.mergered == 0 and patch.status == STATUS_NEW:
                        if patch.tag.repo.name != "linux-next.git":
                            continue
                        if rtype.type != 1:
                            continue
                        if (rtype.flags & TYPE_SCAN_NEXT_ONLY) != 0:
                            continue
                        tststable = dot(stablerepo.dirname(), logger.logger, stablerepo.builddir())
                        tststable.set_token(test.get_token())
                        tststable.set_filename(patch.file)
                        if not os.path.exists(tststable._get_file_path()):
                            continue
                        if tststable.should_patch() and not tststable.has_error():
                            ntag = GitTag.objects.filter(repo__id=stablerepo.id).order_by("-id")
                            if len(ntag) == 0:
                                continue
                            oldtag = patch.tag
                            newtag = ntag[0]
                            oldtag.total = oldtag.total - 1
                            newtag.total = newtag.total + 1
                            oldtag.save()
                            newtag.save()
                            patch.tag = newtag
                            patch.save()
                            pcount["stable"] += 1
                            logger.logger.info("stable patch %d" % patch.id)

                logger.info("End scan type %d" % test.get_type())
                logs.logs = logger.getlog()
                logs.save()
                test.next_token()

        for dot in report_engine_list():
            test = dot(repo.dirname(), logger.logger, repo.builddir())
            for i in range(test.tokens()):
                rtype = None
                try:
                    rtype = Type.objects.filter(id=test.get_type())[0]
                except:
                    test.next_token()
                    continue
                if rtype.status == False:
                    test.next_token()
                    continue

                logger.info("Starting update type %d" % test.get_type())
                if repo.name == "linux-next.git":
                    patchs = Report.objects.filter(
                        Q(type=rtype), Q(status=STATUS_NEW) | Q(status=STATUS_PATCHED) | Q(status=STATUS_SENT)
                    )
                else:
                    patchs = Report.objects.filter(
                        Q(tag__repo=repo),
                        Q(type=rtype),
                        Q(status=STATUS_NEW) | Q(status=STATUS_PATCHED) | Q(status=STATUS_SENT),
                    )
                for patch in patchs:
                    if not patch.mglist is None and len(patch.mglist) != 0:
                        continue

                    if may_reject_cleanup(patch.file):
                        update_patch_status(patch, STATUS_REJECTED)
                        logger.logger.info("rejected patch %d" % patch.id)
                        continue

                    if not os.path.exists(os.path.join(repo.dirname(), patch.file)):
                        update_report_status(patch, STATUS_REMOVED)
                        pcount["removed"] += 1
                        logger.logger.info("removed patch %d" % patch.id)
                        continue

                    test.set_filename(patch.file)
                    should_report = test.should_report()
                    if test.has_error():
                        continue
                    if should_report == False:
                        if patch.status == STATUS_NEW:
                            update_report_status(patch, STATUS_FIXED)
                            pcount["fixed"] += 1
                            logger.logger.info("fixed patch %d" % patch.id)
                        elif patch.status == STATUS_SENT:
                            update_report_status(patch, STATUS_ACCEPTED)
                            pcount["applied"] += 1
                            logger.logger.info("applied patch %d" % patch.id)
                        elif patch.status == STATUS_PATCHED:
                            if patch.mergered != 0:
                                mpatch = Report.objects.filter(id=patch.mergered)
                                if len(mpatch) != 0:
                                    if mpatch[0].status == STATUS_SENT:
                                        update_report_status(patch, STATUS_ACCEPTED)
                                        pcount["applied"] += 1
                                        logger.logger.info("applied patch %d" % patch.id)
                                    else:
                                        update_report_status(patch, STATUS_FIXED)
                                        pcount["fixed"] += 1
                                        logger.logger.info("fixed patch %d" % patch.id)
                                else:
                                    update_report_status(patch, STATUS_FIXED)
                                    pcount["fixed"] += 1
                                    logger.logger.info("fixed patch %d" % patch.id)
                            else:
                                update_report_status(patch, STATUS_FIXED)
                                pcount["fixed"] += 1
                                logger.logger.info("fixed patch %d" % patch.id)
                    elif repo.name == "linux-next.git" and patch.mergered == 0:
                        if patch.tag.repo.name != "linux-next.git":
                            continue
                        if rtype.type != 1:
                            continue
                        if (rtype.flags & TYPE_SCAN_NEXT_ONLY) != 0:
                            continue
                        if not patch.status in [STATUS_NEW, STATUS_PATCHED]:
                            continue
                        tststable = dot(stablerepo.dirname(), logger.logger, stablerepo.builddir())
                        tststable.set_token(test.get_token())
                        tststable.set_filename(patch.file)
                        if not os.path.exists(tststable._get_file_path()):
                            continue
                        if tststable.should_report() and not tststable.has_error():
                            ntag = GitTag.objects.filter(repo__id=stablerepo.id).order_by("-id")
                            if len(ntag) == 0:
                                continue
                            oldtag = patch.tag
                            newtag = ntag[0]
                            oldtag.rptotal = oldtag.rptotal - 1
                            newtag.rptotal = newtag.rptotal + 1
                            oldtag.save()
                            newtag.save()
                            patch.tag = newtag
                            patch.save()
                            pcount["stable"] += 1
                            logger.logger.info("stable patch %d" % patch.id)

                logger.info("End scan type %d" % rtype.id)
                logs.logs = logger.getlog()
                logs.save()
                test.next_token()

        logs.desc = "total checked: %d, removed: %d, fixed: %d, applied: %d, stable: %s" % (
            pcount["total"],
            pcount["removed"],
            pcount["fixed"],
            pcount["applied"],
            pcount["stable"],
        )
        logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
        logs.logs = logger.getlog()
        logs.save()

    return 0
Esempio n. 3
0
def checkreport(repo, rtag, flists):
    git = GitTree(repo.name, repo.dirname(), repo.url, repo.commit, repo.stable)
    count = 0
    scaninfo = []

    logs = ScanLog(reponame = repo.name, tagname = rtag.name,
                   starttime = strftime("%Y-%m-%d %H:%M:%S", localtime()),
                   desc = 'Processing, please wait...')
    logs.save()
    logger = MyLogger()
    logger.info('%d Files changed.' % len(flists))

    for dot in report_engine_list():
        scount = 0
        test = dot(repo.dirname(), logger.logger, repo.builddir())
        for i in range(test.tokens()):
            try:
                rtype = None
                try:
                    rtype = Type.objects.filter(id = test.get_type())[0]
                except:
                    test.next_token()
                    continue
                if rtype.status == False:
                    test.next_token()
                    continue
    
                cmts = GitCommit.objects.filter(repo = repo, type = rtype)
                if len(cmts) == 0:
                    cmt = GitCommit(repo = repo, type = rtype)
                    cmt.save()
                else:
                    cmt = cmts[0]
    
                rflists = flists
                if repo.delta == False:
                    oldcommit = cmt.commit
                    if oldcommit != repo.commit:
                        if git.is_linux_next():
                            oldcommit = git.get_stable()
                        rflists = git.get_changelist(oldcommit, repo.commit, None, True)
                    else:
                        rflists = flists
    
                logger.info('Starting scan type %d, total %d files' % (test.get_type(), len(rflists)))
    
                exceptfiles = []
                for fn in ExceptFile.objects.filter(type = rtype):
                    exceptfiles.append(fn.file)
    
                rcount = 0
                for fname in rflists:
                    if is_source_file(fname) == False:
                        continue
    
                    if exceptfiles.count(fname) != 0:
                        continue
        
                    reports = Report.objects.filter(file = fname, type = rtype)
                    if not os.path.exists(os.path.join(repo.dirname(), fname)):
                        for r in reports:
                            if r.status in [STATUS_NEW, STATUS_PATCHED]:
                                r.status = STATUS_REMOVED
                                r.save()
                        continue
    
                    test.set_filename(fname)
                    should_report = test.should_report()
                    if test.has_error():
                        continue
                    if should_report is False:
                        for r in reports:
                            if r.status in [STATUS_NEW, STATUS_PATCHED]:
                                if r.mergered == 0:
                                    r.status = STATUS_FIXED
                                    r.save()
                                else:
                                    mreport = Report.objects.filter(id = r.mergered)
                                    if len(mreport) != 0:
                                        if mreport[0].status in [STATUS_SENT]:
                                            mreport[0].status = STATUS_ACCEPTED
                                            r.status = STATUS_ACCEPTED
                                        else:
                                            mreport[0].status = STATUS_FIXED
                                            r.status = STATUS_FIXED
                                        mreport[0].save()
                                    else:
                                        r.status = STATUS_FIXED
                                    r.save()
                            elif r.status in [STATUS_SENT]:
                                r.status = STATUS_ACCEPTED
                                r.save()
                        continue
    
                    lcount = 0
                    for r in reports:
                        if r.status in [STATUS_NEW, STATUS_PATCHED, STATUS_SENT]:
                            lcount += 1
    
                    if lcount > 0:
                        continue
    
                    text = test.get_report()
                    report = Report(tag = rtag, file = fname, type = rtype, 
                                    status = STATUS_NEW, reportlog = '\n'.join(text))
                    report.title = rtype.ptitle
                    report.desc = rtype.pdesc
                    report.save()
                    rcount += 1
                    scount += 1
    
                cmt.commit = repo.commit
                cmt.save()
                rtype.commit = repo.commit
                rtype.save()

            except:
                logger.info('Scan ERROR: type %d' % rtype.id)

            logger.info('End scan type %d, report %d' % (rtype.id, rcount))
            logs.logs = logger.getlog()
            logs.save()
            test.next_token()

        count += scount
        scaninfo.append("%s: %d" % (test.name(), scount))

    scaninfo.append("total report: %d" % (count))
    logs.desc = ', '.join(scaninfo)
    logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
    logs.logs = logger.getlog()
    logs.save()

    return count
Esempio n. 4
0
def check_patch(repo, git, rtag, flists, commit):
    count = 0
    scaninfo = []

    logs = ScanLog(reponame = repo.name, tagname = rtag.name,
                   starttime = strftime("%Y-%m-%d %H:%M:%S", localtime()),
                   desc = 'Processing, please wait...')
    logs.save()
    logger = MyLogger()
    logger.logger.info('%d Files changed' % len(flists))
    #logger.logger.info('=' * 40)
    #logger.logger.info('%s' % '\n'.join(flists))
    #logger.logger.info('=' * 40)

    sche_weekend_enable = read_config('patch.schedule.weekend.enable', True)
    sche_weekend_limit = read_config('patch.schedule.weekend.limit', 600)
    sche_weekend_delta = read_config('patch.schedule.weekend.delta', 90)
    sche_obsolete_skip = read_config('patch.schedule.obsolete.skip', False)
    weekday = datetime.datetime.now().weekday()

    for dot in patch_engine_list():
        scount = 0
        test = dot(repo.dirname(), logger.logger, repo.builddir())
        for i in range(test.tokens()):
            try:
                rtype = None
                try:
                    rtype = Type.objects.filter(id = test.get_type())[0]
                except:
                    test.next_token()
                    continue
    
                if rtype.status == False:
                    test.next_token()
                    continue
    
                if (rtype.flags & TYPE_SCAN_NEXT_ONLY) != 0 and not git.is_linux_next():
                    test.next_token()
                    continue
    
                if rtype.type == 0 and sche_weekend_enable is True and len(flists) > sche_weekend_limit and weekday < 5:
                    # if we does not have a patch for this cleanup type in
                    # sche_weekend_limit days, schedule scan only on weekend
                    stime = datetime.datetime.now() - datetime.timedelta(days=sche_weekend_delta)
                    if Patch.objects.filter(type = rtype, date__gte=stime).count() == 0:
                        logger.info('Delay scan type %d to weekend' % test.get_type())
                        test.next_token()
                        continue
    
                cmts = GitCommit.objects.filter(repo = repo, type = rtype)
                if len(cmts) == 0:
                    cmt = GitCommit(repo = repo, type = rtype)
                    cmt.save()
                else:
                    cmt = cmts[0]
    
                if cmt.commit == commit:
                    test.next_token()
                    continue
    
                if repo.delta == False:
                    oldcommit = cmt.commit
                    if oldcommit != repo.commit:
                        if git.is_linux_next():
                            oldcommit = git.get_stable()
                        rflists = git.get_changelist(oldcommit, commit, None, True)
                    else:
                        rflists = flists
                else:
                    rflists = flists
    
                if rtype.type == 0 and sche_weekend_enable is True and len(rflists) > sche_weekend_limit and weekday < 5:
                    stime = datetime.datetime.now() - datetime.timedelta(days=sche_weekend_delta)
                    if Patch.objects.filter(type = rtype, date__gte=stime).count() == 0:
                        logger.info('Delay scan type %d to weekend' % test.get_type())
                        test.next_token()
                        continue
    
                logger.info('Starting scan type %d, total %d files' % (test.get_type(), len(rflists)))
    
                exceptfiles = []
                for fn in ExceptFile.objects.filter(type = rtype):
                    exceptfiles.append(fn.file)
    
                pcount = 0
                for sfile in rflists:
                    if not is_source_file(sfile):
                        continue
    
                    if exceptfiles.count(sfile) != 0:
                        logger.logger.info('skip except file %s, type %d' % (sfile, rtype.id))
                        continue
    
                    # treat patch marked with Rejected as except file
                    if Patch.objects.filter(file = sfile, type = rtype, status = STATUS_REJECTED).count() > 0:
                        continue
    
                    # treat patch marked with Applied and commit is '' as EXISTS patch
                    if Patch.objects.filter(file = sfile, type = rtype, status = STATUS_ACCEPTED, commit = '').count() > 0:
                        continue
    
                    patchs = Patch.objects.filter(file = sfile, type = rtype)
                    rpatchs = []
                    for p in patchs:
                        if not p.status in [STATUS_NEW, STATUS_SENT, STATUS_MARKED]:
                            continue
                        rpatchs.append(p)
    
                    test.set_filename(sfile)
                    # source file maybe removed
                    if not os.path.exists(test._get_file_path()):
                        for p in rpatchs:
                            p.status = STATUS_REMOVED
                            p.save()
                        continue
    
                    # if the same file has a patch for this type, ignore it
                    # because the last patch does not accepted
                    should_patch = test.should_patch()
                    if test.has_error():
                        continue
                    if len(rpatchs) != 0 and should_patch == False:
                        for p in rpatchs:
                            if p.status == STATUS_SENT:
                                p.status = STATUS_ACCEPTED
                            elif p.mergered != 0:
                                mpatch = Patch.objects.filter(id = p.mergered)
                                if len(mpatch) != 0:
                                    if mpatch[0].status == STATUS_SENT:
                                        mpatch[0].status = STATUS_ACCEPTED
                                        p.status = STATUS_ACCEPTED
                                    else:
                                        mpatch[0].status = STATUS_FIXED
                                        p.status = STATUS_FIXED
                                    mpatch[0].save()
                                else:
                                    p.status = STATUS_FIXED
                            else:
                                p.status = STATUS_FIXED
                            p.save()
    
                    if should_patch == True and len(rpatchs) == 0:
                        text = test.get_patch()
    
                        if (rtype.flags & TYPE_CHANGE_DATE_CHECK) == TYPE_CHANGE_DATE_CHECK:
                            if git.is_change_obsoleted(sfile, text) is True:
                                continue
                        elif rtype.id > 3000 and rtype.type == 0 and sche_obsolete_skip is True:
                            if git.is_change_obsoleted(sfile, text) is True:
                                logger.logger.info('skip obsoleted file %s, type %d' % (sfile, rtype.id))
                                continue
    
                        patch = Patch(tag = rtag, file = sfile, type = rtype, 
                                      status = STATUS_NEW, diff = text)
                        patch.save()
    
                        # format patch and cache to patch
                        user = patch.username()
                        email = patch.email()
                        desc = test.get_patch_description()
                        title = test.get_patch_title()
                        if desc is None:
                            desc = rtype.pdesc
                        if title is None:
                            title = rtype.ptitle
                        formater = PatchFormater(repo.dirname(), sfile, user, email, title, desc, text)
                        patch.content = formater.format_patch()
                        patch.title = formater.format_title()
                        patch.desc = formater.format_desc()
                        patch.emails = formater.get_mail_list()
                        patch.module = formater.get_module()
                        patch.save()
    
                        scount += 1
                        pcount += 1
    
                cmt.commit = commit
                cmt.save()
    
            except:
                logger.info('Scan ERROR: type %d' % test.get_type())

            logger.info('End scan type %d, patch %d' % (test.get_type(), pcount))
            logs.logs = logger.getlog()
            logs.save()
            test.next_token()

        count += scount
        scaninfo.append("%s: %d" % (test.name(), scount))

    scaninfo.append("total: %d" % (count))
    logs.desc = ', '.join(scaninfo)
    logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
    logs.logs = logger.getlog()
    logs.save()

    return count
Esempio n. 5
0
def main(args):
    for patch in Patch.objects.filter(commit='', status=STATUS_ACCEPTED):
        if not os.path.exists(
                os.path.join(patch.tag.repo.dirname(), patch.file)):
            continue
        ptitle = re.sub('Subject: \[PATCH[^\]]*]', '', patch.title).strip()
        ptitle = re.sub('^.*:', '', ptitle).strip()
        if len(ptitle) > 2:
            ptitle = ptitle[1:]
        cmds = 'cd %s; git log --author="%s" --pretty="format:%%H|%%s" %s' % (
            patch.tag.repo.dirname(), patch.tag.repo.user, patch.file)
        for line in execute_shell_full(cmds)[::-1]:
            if line.find('|') == -1:
                continue
            rtitle = line.split('|')[1]
            if line.upper().find(ptitle.upper()) == -1 and ptitle.upper().find(
                    rtitle.upper()) == -1:
                continue
            commit = line.split('|')[0]
            if Patch.objects.filter(commit=commit).count() != 0:
                continue
            patch.commit = commit
            patch.save()
            break

    for report in Report.objects.filter(commit='', status=STATUS_ACCEPTED):
        if not os.path.exists(
                os.path.join(patch.tag.repo.dirname(), patch.file)):
            continue
        ptitle = re.sub('Subject: \[PATCH[^\]]*]', '', report.title).strip()
        ptitle = re.sub('^.*:', '', ptitle).strip()
        if len(ptitle) > 2:
            ptitle = ptitle[1:]
        cmds = 'cd %s; git log --author="%s" --pretty="format:%%H|%%s" %s' % (
            report.tag.repo.dirname(), report.tag.repo.user, report.file)
        for line in execute_shell_full(cmds)[::-1]:
            if line.find(ptitle) == -1:
                continue
            commit = line.split('|')[0]
            if Report.objects.filter(commit=commit).count() != 0:
                continue
            report.commit = commit
            report.save()
            break

    stablerepo = None
    for repo in GitRepo.objects.filter(status=True):
        if stablerepo is None:
            stablerepo = repo
        git = GitTree(repo.name, repo.dirname(), repo.url, repo.commit,
                      repo.stable)
        if git.is_linux_next() == True and git.get_commit() == git.get_stable(
        ):
            continue
        logger = MyLogger()
        logs = ScanLog(reponame=repo.name,
                       tagname='-',
                       starttime=strftime("%Y-%m-%d %H:%M:%S", localtime()),
                       desc='Processing, please wait...')
        logs.save()

        for tag in GitTag.objects.filter(repo=repo):
            ptotal = Patch.objects.filter(tag=tag, mergered=0).count()
            rtotal = Report.objects.filter(tag=tag, mergered=0).count()
            if ptotal != tag.total:
                tag.total = ptotal
                tag.save()
            if rtotal != tag.rptotal:
                tag.rptotal = rtotal
                tag.save()
            if tag.running is True:
                tag.running = False
                tag.save()

        pcount = {
            'total': 0,
            'removed': 0,
            'fixed': 0,
            'applied': 0,
            'stable': 0
        }
        for dot in patch_engine_list():
            test = dot(repo.dirname(), logger.logger, repo.builddir())
            for i in range(test.tokens()):
                rtype = None
                try:
                    rtype = Type.objects.filter(id=test.get_type())[0]
                except:
                    test.next_token()
                    continue

                if rtype.status == False:
                    test.next_token()
                    continue

                logger.info('Starting update type %d' % test.get_type())

                if repo.name == 'linux-next.git':
                    patchs = Patch.objects.filter(
                        Q(type=rtype),
                        Q(status=STATUS_NEW) | Q(status=STATUS_SENT))
                else:
                    patchs = Patch.objects.filter(
                        Q(tag__repo=repo), Q(type=rtype),
                        Q(status=STATUS_NEW) | Q(status=STATUS_SENT))

                for patch in patchs:
                    if not patch.mglist is None and len(patch.mglist) != 0:
                        continue
                    test.set_filename(patch.file)
                    pcount['total'] += 1
                    print "check for %s\n" % patch.filename()
                    if may_reject_cleanup(patch.file):
                        update_patch_status(patch, STATUS_REJECTED)
                        logger.logger.info('rejected patch %d' % patch.id)
                        continue

                    if not os.path.exists(test._get_file_path()):
                        update_patch_status(patch, STATUS_REMOVED)
                        pcount['removed'] += 1
                        logger.logger.info('removed patch %d' % patch.id)
                        continue

                    should_patch = test.should_patch()
                    if test.has_error():
                        continue
                    if should_patch == False:
                        if patch.status == STATUS_NEW:
                            if patch.mergered != 0:
                                mpatch = Patch.objects.filter(
                                    id=patch.mergered)
                                if len(mpatch) != 0:
                                    if mpatch[0].status == STATUS_SENT:
                                        update_patch_status(
                                            patch, STATUS_ACCEPTED)
                                        pcount['applied'] += 1
                                        logger.logger.info('applied patch %d' %
                                                           patch.id)
                                    else:
                                        update_patch_status(
                                            patch, STATUS_FIXED)
                                        pcount['fixed'] += 1
                                        logger.logger.info('fixed patch %d' %
                                                           patch.id)
                                else:
                                    update_patch_status(patch, STATUS_FIXED)
                                    pcount['fixed'] += 1
                                    logger.logger.info('fixed patch %d' %
                                                       patch.id)
                            else:
                                update_patch_status(patch, STATUS_FIXED)
                                pcount['fixed'] += 1
                                logger.logger.info('fixed patch %d' % patch.id)
                        elif patch.status == STATUS_SENT:
                            update_patch_status(patch, STATUS_ACCEPTED)
                            pcount['applied'] += 1
                            logger.logger.info('applied patch %d' % patch.id)
                    elif repo.name == 'linux-next.git' and patch.mergered == 0 and patch.status == STATUS_NEW:
                        if patch.tag.repo.name != 'linux-next.git':
                            continue
                        if rtype.type != 1:
                            continue
                        if (rtype.flags & TYPE_SCAN_NEXT_ONLY) != 0:
                            continue
                        tststable = dot(stablerepo.dirname(), logger.logger,
                                        stablerepo.builddir())
                        tststable.set_token(test.get_token())
                        tststable.set_filename(patch.file)
                        if not os.path.exists(tststable._get_file_path()):
                            continue
                        if tststable.should_patch(
                        ) and not tststable.has_error():
                            ntag = GitTag.objects.filter(
                                repo__id=stablerepo.id).order_by("-id")
                            if len(ntag) == 0:
                                continue
                            oldtag = patch.tag
                            newtag = ntag[0]
                            oldtag.total = oldtag.total - 1
                            newtag.total = newtag.total + 1
                            oldtag.save()
                            newtag.save()
                            patch.tag = newtag
                            patch.save()
                            pcount['stable'] += 1
                            logger.logger.info('stable patch %d' % patch.id)

                logger.info('End scan type %d' % test.get_type())
                logs.logs = logger.getlog()
                logs.save()
                test.next_token()

        for dot in report_engine_list():
            test = dot(repo.dirname(), logger.logger, repo.builddir())
            for i in range(test.tokens()):
                rtype = None
                try:
                    rtype = Type.objects.filter(id=test.get_type())[0]
                except:
                    test.next_token()
                    continue
                if rtype.status == False:
                    test.next_token()
                    continue

                logger.info('Starting update type %d' % test.get_type())
                if repo.name == 'linux-next.git':
                    patchs = Report.objects.filter(
                        Q(type=rtype),
                        Q(status=STATUS_NEW) | Q(status=STATUS_PATCHED)
                        | Q(status=STATUS_SENT))
                else:
                    patchs = Report.objects.filter(
                        Q(tag__repo=repo), Q(type=rtype),
                        Q(status=STATUS_NEW) | Q(status=STATUS_PATCHED)
                        | Q(status=STATUS_SENT))
                for patch in patchs:
                    if not patch.mglist is None and len(patch.mglist) != 0:
                        continue

                    if may_reject_cleanup(patch.file):
                        update_patch_status(patch, STATUS_REJECTED)
                        logger.logger.info('rejected patch %d' % patch.id)
                        continue

                    if not os.path.exists(
                            os.path.join(repo.dirname(), patch.file)):
                        update_report_status(patch, STATUS_REMOVED)
                        pcount['removed'] += 1
                        logger.logger.info('removed patch %d' % patch.id)
                        continue

                    test.set_filename(patch.file)
                    should_report = test.should_report()
                    if test.has_error():
                        continue
                    if should_report == False:
                        if patch.status == STATUS_NEW:
                            update_report_status(patch, STATUS_FIXED)
                            pcount['fixed'] += 1
                            logger.logger.info('fixed patch %d' % patch.id)
                        elif patch.status == STATUS_SENT:
                            update_report_status(patch, STATUS_ACCEPTED)
                            pcount['applied'] += 1
                            logger.logger.info('applied patch %d' % patch.id)
                        elif patch.status == STATUS_PATCHED:
                            if patch.mergered != 0:
                                mpatch = Report.objects.filter(
                                    id=patch.mergered)
                                if len(mpatch) != 0:
                                    if mpatch[0].status == STATUS_SENT:
                                        update_report_status(
                                            patch, STATUS_ACCEPTED)
                                        pcount['applied'] += 1
                                        logger.logger.info('applied patch %d' %
                                                           patch.id)
                                    else:
                                        update_report_status(
                                            patch, STATUS_FIXED)
                                        pcount['fixed'] += 1
                                        logger.logger.info('fixed patch %d' %
                                                           patch.id)
                                else:
                                    update_report_status(patch, STATUS_FIXED)
                                    pcount['fixed'] += 1
                                    logger.logger.info('fixed patch %d' %
                                                       patch.id)
                            else:
                                update_report_status(patch, STATUS_FIXED)
                                pcount['fixed'] += 1
                                logger.logger.info('fixed patch %d' % patch.id)
                    elif repo.name == 'linux-next.git' and patch.mergered == 0:
                        if patch.tag.repo.name != 'linux-next.git':
                            continue
                        if rtype.type != 1:
                            continue
                        if (rtype.flags & TYPE_SCAN_NEXT_ONLY) != 0:
                            continue
                        if not patch.status in [STATUS_NEW, STATUS_PATCHED]:
                            continue
                        tststable = dot(stablerepo.dirname(), logger.logger,
                                        stablerepo.builddir())
                        tststable.set_token(test.get_token())
                        tststable.set_filename(patch.file)
                        if not os.path.exists(tststable._get_file_path()):
                            continue
                        if tststable.should_report(
                        ) and not tststable.has_error():
                            ntag = GitTag.objects.filter(
                                repo__id=stablerepo.id).order_by("-id")
                            if len(ntag) == 0:
                                continue
                            oldtag = patch.tag
                            newtag = ntag[0]
                            oldtag.rptotal = oldtag.rptotal - 1
                            newtag.rptotal = newtag.rptotal + 1
                            oldtag.save()
                            newtag.save()
                            patch.tag = newtag
                            patch.save()
                            pcount['stable'] += 1
                            logger.logger.info('stable patch %d' % patch.id)

                logger.info('End scan type %d' % rtype.id)
                logs.logs = logger.getlog()
                logs.save()
                test.next_token()

        logs.desc = 'total checked: %d, removed: %d, fixed: %d, applied: %d, stable: %s' % (
            pcount['total'], pcount['removed'], pcount['fixed'],
            pcount['applied'], pcount['stable'])
        logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
        logs.logs = logger.getlog()
        logs.save()

    return 0
Esempio n. 6
0
def main(args):
    buildpatch = True
    buildreport = True
    rebuildrepo = True
    repoid = None
    if len(args) > 1:
        arg = args[1]
        if arg == 'patch':
            buildreport = False
            rebuildrepo = False
        elif arg == 'report':
            buildpatch = False
            rebuildrepo = False

    if len(args) > 2:
        repoid = int(args[2])

    for repo in GitRepo.objects.filter(status=True, build=True):
        if repoid != None and repoid != repo.id:
            continue

        patchcnt = Patch.objects.filter(tag__repo=repo,
                                        build=0,
                                        mergered=0,
                                        status=STATUS_NEW).count()
        reportcnt = Report.objects.filter(tag__repo=repo,
                                          build=0,
                                          mergered=0,
                                          status=STATUS_PATCHED).count()
        if (buildpatch == False or patchcnt == 0) and (buildreport == False
                                                       or reportcnt == 0):
            continue

        logger = MyLogger()
        logs = ScanLog(reponame=repo.name,
                       tagname='-',
                       starttime=strftime("%Y-%m-%d %H:%M:%S", localtime()),
                       desc='Building, please wait...')
        logs.save()

        pcount = {'total': 0, 'pass': 0, 'fail': 0}
        rcount = {'total': 0, 'pass': 0, 'fail': 0}
        # prepare build env
        gitlog = ''
        if not os.path.exists(repo.builddir()):
            os.system("cd %s; git clone file://%s" %
                      (os.path.dirname(repo.builddir()), repo.dirname()))
            if repo.name == 'linux-next.git':
                os.system(
                    "cd %s; cp %s/.git/refs/remotes/origin/stable .git/refs/remotes/stable"
                    % (repo.builddir(), repo.dirname()))
            os.system("cd %s; make allmodconfig" % repo.builddir())
            rebuildrepo = True
        elif rebuildrepo == True:
            if repo.name == 'linux-next.git':
                if is_linux_next_update(repo):
                    os.system("cd %s; git reset --hard %s" %
                              (repo.builddir(), get_linux_next_stable(repo)))
                    ret, tmplog = execute_shell_log(
                        "cd %s; git pull" % repo.builddir(), logger)
                    gitlog = tmplog
                    os.system(
                        "cd %s; cp %s/.git/refs/remotes/origin/stable .git/refs/remotes/stable"
                        % (repo.builddir(), repo.dirname()))
                    os.system("cd %s; make allmodconfig" % repo.builddir())
                else:
                    gitlog = 'Already up-to-date.'
            else:
                os.system("cd %s; git reset --hard" % repo.builddir())
                ret, tmplog = execute_shell_log(
                    "cd %s; git pull" % repo.builddir(), logger)
                gitlog = tmplog

        #if rebuildrepo == True and gitlog.find('Already up-to-date.') == -1:
        #    execute_shell("cd %s; make" % repo.builddir(), logger)

        commit = commit_from_repo(repo)

        if buildpatch == True:
            for patch in Patch.objects.filter(tag__repo=repo,
                                              build=0,
                                              mergered=0,
                                              status=STATUS_NEW):
                buildlog = ''

                if patch.file.find(
                        'arch/') == 0 and patch.file.find('arch/x86') != 0:
                    patch.build = 3
                    patch.save()
                    continue

                pcount['total'] += 1
                fname = os.path.join(patch.dirname(), patch.filename())
                pdiff = open(fname, "w")
                try:
                    pdiff.write(patch.content)
                except:
                    pdiff.write(unicode.encode(patch.content, 'utf-8'))
                pdiff.close()

                print "build for patch %s...\n" % os.path.basename(fname)
                logger.logger.info("build for patch %s..." %
                                   os.path.basename(fname))

                execute_shell(
                    "cd %s; git reset --hard %s" % (repo.builddir(), commit),
                    logger)
                if os.path.exists(
                        os.path.join(repo.builddir(), '.git/rebase-apply')):
                    execute_shell("cd %s; rm -rf .git/rebase-apply" %
                                  repo.builddir())

                objfile = "%s.o" % patch.file[:-2]
                if patch.type.flags & TYPE_BUILD_SPARSE_CHECK:
                    if not os.path.isdir(
                            os.path.join(repo.builddir(), patch.file)):
                        buildlog += '# make C=2 %s\n' % objfile
                        ret, log = execute_shell_log(
                            "cd %s; make C=2 %s" % (repo.builddir(), objfile),
                            logger)
                        buildlog += log
                        buildlog += '\n'

                    dname = os.path.dirname(patch.file)
                    if len(dname.split(os.sep)) > 2:
                        buildlog += '# make C=2 M=%s\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make C=2 M=%s" % (repo.builddir(), dname),
                            logger)
                        buildlog += log
                        buildlog += '\n'

                ret, log = execute_shell_log(
                    "cd %s; git am %s" % (repo.builddir(), fname), logger)
                buildlog += '# git am %s\n' % os.path.basename(fname)
                buildlog += log
                if ret != 0:
                    pcount['fail'] += 1
                    patch.build = 2
                    patch.buildlog = buildlog
                    patch.save()
                    continue

                if patch.file.find('tools/') == 0:
                    dname = os.path.dirname(patch.file)
                    while len(dname) != 0 and not os.path.exists(
                            os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# cd %s; make\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make" %
                            (os.path.join(repo.builddir(), dname)), logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            patch.build = 2
                            patch.buildlog = buildlog
                            patch.save()
                            continue
                    else:
                        buildlog += 'do not known how to build\n'
                    log += '\nLD [M] %s\n' % objfile

                if patch.file.find('include/') != 0 and patch.file.find(
                        'tools/') != 0:
                    dname = os.path.dirname(patch.file)
                    while len(dname) != 0 and not os.path.exists(
                            os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# make M=%s\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make M=%s" % (repo.builddir(), dname),
                            logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            patch.build = 2
                            patch.buildlog = buildlog
                            patch.save()
                            continue

                output = log
                if is_c_file(patch.file) and is_module_build(
                        patch.file, output) == False:
                    buildlog += '\n# make %s\n' % objfile
                    ret, log = execute_shell_log(
                        "cd %s; make %s" % (repo.builddir(), objfile), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        patch.build = 2
                        patch.buildlog = buildlog
                        patch.save()
                        if buildlog.find(
                                "Run 'make oldconfig' to update configuration."
                        ) != -1:
                            os.system("cd %s; make allmodconfig" %
                                      repo.builddir())
                        continue
                    output = log
                    if output.find(objfile) != -1:
                        log += '\nLD [M] %s\n' % objfile

                output = log
                if patch.file.find('include/') == 0 or is_module_build(
                        patch.file, output) == False:
                    buildlog += '\n# make vmlinux\n'
                    ret, log = execute_shell_log(
                        "cd %s; make vmlinux" % (repo.builddir()), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        patch.build = 2
                        patch.buildlog = buildlog
                        patch.save()
                        if buildlog.find(
                                "Run 'make oldconfig' to update configuration."
                        ) != -1:
                            os.system("cd %s; make allmodconfig" %
                                      repo.builddir())
                        continue

                if patch.type.flags & TYPE_BUILD_SPARSE_CHECK:
                    if not os.path.isdir(
                            os.path.join(repo.builddir(), patch.file)):
                        buildlog += '# make C=2 %s\n' % objfile
                        ret, log = execute_shell_log(
                            "cd %s; make C=2 %s" % (repo.builddir(), objfile),
                            logger)
                        buildlog += log
                        buildlog += '\n'

                    dname = os.path.dirname(patch.file)
                    if len(dname.split(os.sep)) > 2:
                        buildlog += '# make C=2 M=%s\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make C=2 M=%s" % (repo.builddir(), dname),
                            logger)
                        buildlog += log
                        buildlog += '\n'

                pcount['pass'] += 1
                if buildlog.find(': warning: ') != -1:
                    patch.build = 4
                else:
                    patch.build = 1
                patch.buildlog = buildlog
                patch.save()

        if buildreport == True:
            for report in Report.objects.filter(tag__repo=repo,
                                                build=0,
                                                mergered=0,
                                                status=STATUS_PATCHED):
                buildlog = ''

                if report.file.find(
                        'arch/') == 0 and report.file.find('arch/x86') != 0:
                    report.build = 3
                    report.save()
                    continue

                rcount['total'] += 1
                fname = os.path.join(report.dirname(), report.filename())
                pdiff = open(fname, "w")
                try:
                    pdiff.write(report.content)
                except:
                    pdiff.write(unicode.encode(report.content, 'utf-8'))
                pdiff.close()

                print "build for report patch %s...\n" % os.path.basename(
                    fname)
                logger.logger.info("build for report patch %s..." %
                                   os.path.basename(fname))

                execute_shell(
                    "cd %s; git reset --hard %s" % (repo.builddir(), commit),
                    logger)
                if os.path.exists(
                        os.path.join(repo.builddir(), '.git/rebase-apply')):
                    execute_shell("cd %s; rm -rf .git/rebase-apply" %
                                  repo.builddir())

                ret, log = execute_shell_log(
                    "cd %s; git am %s" % (repo.builddir(), fname), logger)
                buildlog += '# git am %s\n' % os.path.basename(fname)
                buildlog += log
                if ret != 0:
                    rcount['fail'] += 1
                    report.build = 2
                    report.buildlog = buildlog
                    report.save()
                    continue

                if report.file.find('tools/') == 0:
                    dname = os.path.dirname(report.file)
                    while len(dname) != 0 and not os.path.exists(
                            os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# cd %s; make\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make" %
                            (os.path.join(repo.builddir(), dname)), logger)
                        buildlog += log
                        if ret != 0:
                            pcount['fail'] += 1
                            report.build = 2
                            report.buildlog = buildlog
                            report.save()
                            continue
                    else:
                        buildlog += 'do not known how to build\n'
                    log += '\nLD [M] %s\n' % objfile

                objfile = "%s.o" % report.file[:-2]
                if report.file.find('include/') != 0 and report.file.find(
                        'tools/') != 0:
                    dname = os.path.dirname(report.file)
                    while len(dname) != 0 and not os.path.exists(
                            os.path.join(repo.builddir(), dname, 'Makefile')):
                        dname = os.path.dirname(dname)
                    if len(dname) != 0:
                        buildlog += '\n# make M=%s\n' % dname
                        ret, log = execute_shell_log(
                            "cd %s; make M=%s" % (repo.builddir(), dname),
                            logger)
                        buildlog += log
                        if ret != 0:
                            rcount['fail'] += 1
                            report.build = 2
                            report.buildlog = buildlog
                            report.save()
                            continue

                output = log
                if is_c_file(report.file) and is_module_build(
                        report.file, output) == False:
                    buildlog += '\n# make %s\n' % objfile
                    ret, log = execute_shell_log(
                        "cd %s; make %s" % (repo.builddir(), objfile), logger)
                    buildlog += log
                    if ret != 0:
                        pcount['fail'] += 1
                        report.build = 2
                        report.buildlog = buildlog
                        report.save()
                        if buildlog.find(
                                "Run 'make oldconfig' to update configuration."
                        ) != -1:
                            os.system("cd %s; make allmodconfig" %
                                      repo.builddir())
                        continue
                    output = log
                    if output.find(objfile) != -1:
                        log += '\nLD [M] %s\n' % objfile

                output = log
                if report.file.find('include/') == 0 or is_module_build(
                        report.file, output) == False:
                    buildlog += '\n# make vmlinux\n'
                    ret, log = execute_shell_log(
                        "cd %s; make vmlinux" % (repo.builddir()), logger)
                    buildlog += log
                    if ret != 0:
                        rcount['fail'] += 1
                        report.build = 2
                        report.buildlog = buildlog
                        report.save()
                        continue

                rcount['pass'] += 1
                if buildlog.find(': warning: ') != -1:
                    report.build = 4
                else:
                    report.build = 1
                report.buildlog = buildlog
                report.save()

        logs.desc = 'build patch: %d, pass: %d fail:%d, build report: %s, pass: %d, fail: %s' \
                    % (pcount['total'], pcount['pass'], pcount['fail'], rcount['total'], rcount['pass'], rcount['fail'])
        logs.endtime = strftime("%Y-%m-%d %H:%M:%S", localtime())
        logs.logs = logger.getlog()
        logs.save()

        os.system("cd %s; git reset --hard %s" % (repo.builddir(), commit))