Example #1
0
def importcoccireport(fname, lines, title, options, desc, content, efiles):
    name = os.path.splitext(fname)[0]

    if CocciReportEngine.objects.filter(file=fname).count() != 0:
        print 'skip %s, already exists' % fname
        return False

    engine = CocciReportEngine(file=fname, content=content, options=options)
    try:
        cocci = open(engine.fullpath(), "w")
        cocci.writelines(lines)
        cocci.close()
    except:
        print 'ERROR: can not write file %s' % engine.fullpath()
        return False

    engine.save()

    rtype = Type(id=engine.id + 10000,
                 name=name,
                 ptitle=title,
                 pdesc=desc,
                 status=False)
    rtype.save()

    for finfo in efiles:
        efile = ExceptFile(type=rtype,
                           file=finfo['file'],
                           reason=finfo['reason'])
        efile.save()

    return True
Example #2
0
def patch_special(request):
    pids = get_request_paramter(request, 'ids')
    if pids is None:
        return HttpResponse('SPECIAL ERROR: no patch id specified')

    ids = pids.split(',')
    patchs = []
    for i in ids:
        patch = Patch.objects.filter(id = i)
        if len(patch) == 0:
            logevent("SPECIAL: patch [%s], ERROR: patch %s does not exists" % (pids, i))
            return HttpResponse('SPECIAL ERROR: patch %s does not exists' % i)
        patchs.append(patch[0])

    for patch in patchs:
        rtype = patch.type
        fname = patch.file
        reason = 'special case that can not detect correctly'

        if ExceptFile.objects.filter(type = rtype, file = fname).count() == 0:
            einfo = ExceptFile(type = rtype, file = fname, reason = reason)
            einfo.save()

    logevent("SPECIAL: patch [%s], SUCCEED" % pids, True)
    return HttpResponse('SPECIAL SUCCEED: patch ids [%s]' % pids)
Example #3
0
def importcoccireport(fname, lines, title, options, desc, content, efiles):
    name = os.path.splitext(fname)[0]
    
    if CocciReportEngine.objects.filter(file = fname).count() != 0:
        print 'skip %s, already exists' % fname
        return False

    engine = CocciReportEngine(file = fname, content = content, options = options)
    try:
        cocci = open(engine.fullpath(), "w")
        cocci.writelines(lines)
        cocci.close()
    except:
        print 'ERROR: can not write file %s' % engine.fullpath()
        return False

    engine.save()

    rtype = Type(id = engine.id + 10000, name = name, ptitle = title, pdesc = desc, status = False)
    rtype.save()
    
    for finfo in efiles:
        efile = ExceptFile(type = rtype, file = finfo['file'], reason = finfo['reason'])
        efile.save()

    return True
Example #4
0
def exceptfile_new(request):
    if request.method == "POST":
        typeid = get_request_paramter(request, "type")
        fname = get_request_paramter(request, "file")
        reason = get_request_paramter(request, "reason")

        rtypes = Type.objects.filter(id=typeid)
        if len(rtypes) == 0:
            logevent("NEW: except file, ERROR: type id %s does not exists" % typeid)
            return HttpResponse("NEW: except file, ERROR: type id %s does not exists" % typeid)

        einfo = ExceptFile(type=rtypes[0], file=fname, reason=reason)
        einfo.save()

        if int(typeid) > 3000:
            coccis = CocciReportEngine.objects.filter(id=int(typeid) - 3000)
            if len(coccis) > 0:
                rewrite_engine(coccis[0])

        logevent("NEW: except file, SUCCEED: new id %s" % einfo.id, True)
        return HttpResponse("NEW: except file, SUCCEED")
    else:
        context = RequestContext(request)
        context["form"] = ExceptFileForm()
        return render_to_response("engine/exceptfilesedit.html", context)
Example #5
0
def report_special(request):
    pids = get_request_paramter(request, 'ids')
    if pids is None:
        return HttpResponse('SPECIAL ERROR: no report id specified')

    ids = pids.split(',')
    reports = []
    for i in ids:
        report = Report.objects.filter(id = i)
        if len(report) == 0:
            logevent("SPECIAL: report [%s], ERROR: patch %s does not exists" % (pids, i))
            return HttpResponse('SPECIAL ERROR: patch %s does not exists' % i)
        reports.append(report[0])

    for report in reports:
        rtype = report.type
        fname = report.file
        reason = 'special case that can not detect correctly'

        if ExceptFile.objects.filter(type = rtype, file = fname).count() == 0:
            einfo = ExceptFile(type = rtype, file = fname, reason = reason)
            einfo.save()

    logevent("SPECIAL: report [%s], SUCCEED" % pids, True)
    return HttpResponse('SPECIAL SUCCEED: patch ids [%s]' % pids)
Example #6
0
def exceptfile_new(request):
    if request.method == "POST":
        typeid = get_request_paramter(request, 'type')
        fname = get_request_paramter(request, 'file')
        reason = get_request_paramter(request, 'reason')

        rtypes = Type.objects.filter(id = typeid)
        if len(rtypes) == 0:
            logevent("NEW: except file, ERROR: type id %s does not exists" % typeid)
            return HttpResponse('NEW: except file, ERROR: type id %s does not exists' % typeid)

        einfo = ExceptFile(type = rtypes[0], file = fname, reason = reason)
        einfo.save()

        if int(typeid) > 3000:
            coccis = CocciReportEngine.objects.filter(id = int(typeid) - 3000)
            if len(coccis) > 0:
                rewrite_engine(coccis[0])

        logevent("NEW: except file, SUCCEED: new id %s" % einfo.id, True)
        return HttpResponse('NEW: except file, SUCCEED')
    else:
        context = RequestContext(request)
        context['form'] = ExceptFileForm()
        return render_to_response("engine/exceptfilesedit.html", context)
Example #7
0
def report_special(request):
    pids = get_request_paramter(request, "ids")
    if pids is None:
        return HttpResponse("SPECIAL ERROR: no report id specified")

    ids = pids.split(",")
    reports = []
    for i in ids:
        report = Report.objects.filter(id=i)
        if len(report) == 0:
            logevent("SPECIAL: report [%s], ERROR: patch %s does not exists" % (pids, i))
            return HttpResponse("SPECIAL ERROR: patch %s does not exists" % i)
        reports.append(report[0])

    for report in reports:
        rtype = report.type
        fname = report.file
        reason = "special case that can not detect correctly"

        if ExceptFile.objects.filter(type=rtype, file=fname).count() == 0:
            einfo = ExceptFile(type=rtype, file=fname, reason=reason)
            einfo.save()

    logevent("SPECIAL: report [%s], SUCCEED" % pids, True)
    return HttpResponse("SPECIAL SUCCEED: patch ids [%s]" % pids)