Exemplo n.º 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
Exemplo n.º 2
0
def semantic_move_to_report(request):
    sids = get_request_paramter(request, 'ids')
    if sids is None:
        return HttpResponse('MOVE ERROR: no semantic id specified')

    ids = sids.split(',')
    coccis = []
    for i in ids:
        cocci = CocciPatchEngine.objects.filter(id = i)
        if len(cocci) == 0:
            logevent("MOVE: coccinelle semantic [%s], ERROR: id %s does not exists" % (sids, i))
            return HttpResponse('MOVE ERROR: id %s does not exists' % i)
        coccis.append(cocci[0])

    for cocci in coccis:
        rtypes = Type.objects.filter(id = cocci.id + 3000)
        if len(rtypes) != 0:
            rtype = rtypes[0]

            patchs = Patch.objects.filter(type = rtype)
            efiles = ExceptFile.objects.filter(type = rtype)

            ncocci = CocciReportEngine(file = cocci.file, options = cocci.options, content = cocci.content)
            ncocci.save()
            rewrite_report_engine(ncocci)

            rtype.id = ncocci.id + 10000
            rtype.save()

            # move patchs owner by this type
            for patch in patchs:
                report = Report(tag = patch.tag, type = rtype, status = patch.status,
                                file = patch.file, date = patch.date, mergered = 0,
                                mglist = '', commit = patch.commit, reportlog = patch.diff,
                                diff = patch.diff, title = patch.title, desc = patch.desc,
                                emails = patch.emails, content = patch.content,
                                build = patch.build, buildlog = patch.buildlog)
                report.save()
                tag = patch.tag
                patch.delete()
                tag.total -= 1
                tag.rptotal += 1
                tag.save()

            # delete except files owner by this type
            for efile in efiles:
                efile.type = rtype
                efile.save()

        if os.path.exists(cocci.fullpath()):
            os.unlink(cocci.fullpath())
        cocci.delete()

    logevent("MOVE: coccinelle semantic [%s], SUCCEED" % sids, True)
    return HttpResponse('MOVE SUCCEED: engine ids [%s]' % sids)
Exemplo n.º 3
0
def report_semantic_new(request):
    if request.method == "POST":
        name = get_request_paramter(request, 'name')
        title = get_request_paramter(request, 'title')
        desc = get_request_paramter(request, 'desc')
        content = get_request_paramter(request, 'content')
        options = get_request_paramter(request, 'options')

        if name is None or len(name) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no name specified")
            return HttpResponse('NEW ERROR: no semantic name specified')
    
        if title is None or len(title) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no title specified")
            return HttpResponse('NEW ERROR: no semantic title specified')
    
        if desc is None or len(desc) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no desc specified")
            return HttpResponse('NEW ERROR: no semantic desc specified')
    
        if content is None or len(content) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no content specified")
            return HttpResponse('NEW ERROR: no semantic content specified')
    
        if options is None:
            options = ''

        fname = '%s.cocci' % name.strip()
        engine = CocciReportEngine(file = fname, content = content, options = options)
        if os.path.exists(engine.fullpath()):
            logevent("NEW: coccinelle report semantic, ERROR: name %s already exists" % name)
            return HttpResponse('NEW ERROR: semantic name %s already exists' % name)

        spctx = engine.rawformat(title, desc)
        try:
            cocci = open(engine.fullpath(), "w")
            cocci.write(spctx)
            cocci.close()
        except:
            logevent("NEW: coccinelle report semantic, ERROR: can not write file %s" % engine.fullpath())
            return HttpResponse('NEW ERROR: can not write file %s' % engine.fullpath())
    
        engine.save()
    
        rtype = Type(id = engine.id + 10000, name = name, ptitle = title, pdesc = desc, status = False)
        rtype.save()
    
        logevent("NEW: coccinelle report semantic, SUCCEED: new type id %s" % rtype.id, True)
        return HttpResponse('NEW: coccinelle report semanticm, SUCCEED: new type %s' % rtype.id)
    else:
        context = RequestContext(request)
        return render_to_response("engine/reportedit.html", context)
Exemplo n.º 4
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
Exemplo n.º 5
0
def report_semantic_new(request):
    if request.method == "POST":
        name = get_request_paramter(request, "name")
        title = get_request_paramter(request, "title")
        desc = get_request_paramter(request, "desc")
        content = get_request_paramter(request, "content")
        options = get_request_paramter(request, "options")

        if name is None or len(name) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no name specified")
            return HttpResponse("NEW ERROR: no semantic name specified")

        if title is None or len(title) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no title specified")
            return HttpResponse("NEW ERROR: no semantic title specified")

        if desc is None or len(desc) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no desc specified")
            return HttpResponse("NEW ERROR: no semantic desc specified")

        if content is None or len(content) == 0:
            logevent("NEW: coccinelle report semantic, ERROR: no content specified")
            return HttpResponse("NEW ERROR: no semantic content specified")

        if options is None:
            options = ""

        fname = "%s.cocci" % name.strip()
        engine = CocciReportEngine(file=fname, content=content, options=options)
        if os.path.exists(engine.fullpath()):
            logevent("NEW: coccinelle report semantic, ERROR: name %s already exists" % name)
            return HttpResponse("NEW ERROR: semantic name %s already exists" % name)

        spctx = engine.rawformat(title, desc)
        try:
            cocci = open(engine.fullpath(), "w")
            cocci.write(spctx)
            cocci.close()
        except:
            logevent("NEW: coccinelle report semantic, ERROR: can not write file %s" % engine.fullpath())
            return HttpResponse("NEW ERROR: can not write file %s" % engine.fullpath())

        engine.save()

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

        logevent("NEW: coccinelle report semantic, SUCCEED: new type id %s" % rtype.id, True)
        return HttpResponse("NEW: coccinelle report semanticm, SUCCEED: new type %s" % rtype.id)
    else:
        context = RequestContext(request)
        return render_to_response("engine/reportedit.html", context)