Exemple #1
0
def importcoccipatch(fname, lines, title, fixed, options, desc, content, efiles):
    name = os.path.splitext(fname)[0]
    
    if CocciPatchEngine.objects.filter(file = fname).count() != 0:
        print 'skip %s, already exists' % fname
        return False

    engine = CocciPatchEngine(file = fname, content = content, options = options, fixed = fixed)
    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 + 3000, 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
Exemple #2
0
def 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')
        fixed = get_request_paramter(request, 'fixed')

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

        if fixed is None:
            fixed = ''

        fname = '%s.cocci' % name.strip()
        engine = CocciPatchEngine(file = fname, content = content, options = options, fixed = fixed.strip())
        if os.path.exists(engine.fullpath()):
            logevent("NEW: coccinelle 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 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 + 3000, name = name, ptitle = title, pdesc = desc, status = False)
        rtype.save()
    
        logevent("NEW: coccinelle semantic, SUCCEED: new type id %s" % rtype.id, True)
        return HttpResponse('NEW: coccinelle semanticm, SUCCEED: new type %s' % rtype.id)
    else:
        context = RequestContext(request)
        return render_to_response("engine/semanticedit.html", context)
Exemple #3
0
def 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")
        fixed = get_request_paramter(request, "fixed")

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

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

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

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

        if options is None:
            options = ""

        if fixed is None:
            fixed = ""

        fname = "%s.cocci" % name.strip()
        engine = CocciPatchEngine(file=fname, content=content, options=options, fixed=fixed.strip())
        if os.path.exists(engine.fullpath()):
            logevent("NEW: coccinelle 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 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 + 3000, name=name, ptitle=title, pdesc=desc, status=False)
        rtype.save()

        logevent("NEW: coccinelle semantic, SUCCEED: new type id %s" % rtype.id, True)
        return HttpResponse("NEW: coccinelle semanticm, SUCCEED: new type %s" % rtype.id)
    else:
        context = RequestContext(request)
        return render_to_response("engine/semanticedit.html", context)
Exemple #4
0
def importcoccipatch(fname, lines, title, fixed, options, desc, content,
                     efiles):
    name = os.path.splitext(fname)[0]

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

    engine = CocciPatchEngine(file=fname,
                              content=content,
                              options=options,
                              fixed=fixed)
    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 + 3000,
                 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