Пример #1
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
Пример #2
0
def main(args):
    django.setup()

    for repo in GitRepo.objects.all():
        # repo is disabled
        if repo.status == False:
            continue

        git = GitTree(repo.name, repo.dirname(), repo.url, repo.commit, repo.stable)
        otag = git.get_tag()
        if git.check_update() == False and repo.delta == True:
            rtags = GitTag.objects.filter(repo = repo, name = otag)
            if len(rtags) > 0:
                rtag = rtags[0]
                rtag.flist = ''
                rtag.save()
            continue

        # update build tree
        _burl = "file://%s" % repo.dirname()
        buildgit = GitTree(repo.name, repo.builddir(), _burl, repo.commit, repo.stable)
        buildgit.update()

        # the tag name after git pull
        ntag = git.get_tag()
        if otag is None:
            otag = ntag

        if git.is_linux_next() == True:
            tag = ntag
        else:
            tag = otag
        if tag != ntag:
            # we got a new tag, just scan from last commit to otag
            # as common, new tag is the last commit, so does not need
            # to scan twice
            commit = git.get_commit_by_tag(ntag)
        else:
            commit = git.get_commit()

        if git.is_linux_next() == True and commit == git.get_stable():
            # we update linux-next tree failed
            continue

        # if delta scan is enbled, skip the first time since we git clone
        # the tree, treat there is no file change
        if repo.delta == True:
            if repo.commit is None or len(repo.commit) == 0:
                repo.commit = commit
                repo.save()
                continue

            # no file change
            if repo.commit == commit:
                continue

        # file change list from last update
        flists = git.get_changelist(repo.commit, commit, repo.update) 

        tags = GitTag.objects.filter(repo = repo, name = tag)
        rtag = None
        if tags.count() == 0:
            rtag = GitTag(repo = repo, name = tag, flist = ','.join(flists), total = 0)
            rtag.save()
        else:
            rtag = tags[0]

        if rtag.running == True:
            continue

        rtag.running = True
        rtag.save()

        print "Check for repo %s" % os.path.basename(repo.url)
        try:
            pcount = check_patch(repo, git, rtag, flists, commit)
        except:
            pass

        rtag.total += pcount
        rtag.flist = ','.join(flists)
        rtag.running = False
        rtag.save()

        repo.commit = commit
        if git.is_linux_next():
            repo.stable = git.get_stable()
        repo.update = git.get_update_date()
        repo.save()
        print "Total patch %d" % pcount

    return 0
Пример #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
Пример #4
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