Example #1
0
def ajax_add_funcgraph_link(request, f, d, x):
    """
    
    """
    valid_method_or_404(request, ["POST",])
    dajax = Dajax()

    try : depth = int(d)
    except ValueError : depth = -1
    xref = x if x is not None else True
    
    try :
         for obj in serializers.deserialize("xml", f):
            data = obj
            data.save()
            break
            
         caller_f = data.object

         if not isinstance(caller_f, Function):
             return dajax.json()
        
         project = caller_f.project
         
         if not project.is_parsed:
             return dajax.json()
         
    except xml.sax.SAXParseException:
        return dajax.json()

    
    project = caller_f.project
    if f:
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id, "up", depth)
    else :
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id, "down", depth)
    hashed_basename = hashlib.sha256(base).hexdigest() + ".svg"
    pic_name = unipath.Path(settings.CACHE_PATH + "/" + hashed_basename)

    if not pic_name.isfile():
        ret, err = generate_graph(pic_name, project, caller_f, xref, depth)
        if ret==False :
            return dajax.json()

    fmt_str = "<tr>"
    fmt_str+= "<td width=\"40%\">{0}</td>"
    fmt_str+= "<td width=\"15%\">{1}</td>"
    fmt_str+= "<td width=\"15%\">{2}</td>"
    fmt_str+= "<td width=\"30%\"><a href=\"{3}\">{0}</a></td>"
    fmt_str+= "</tr>"

    line = fmt_str.format(caller_f.name,
                          xref,
                          depth,
                          reverse('browser.views.get_cache',args=(hashed_basename,)))
    dajax.assign('#table-graphs', 'innerHTML', line)
    return dajax.json()
Example #2
0
def project_draw(request, project_id):
    """
    
    """
    valid_method_or_404(request, ["GET",])
    
    project = get_object_or_404(Project, pk=project_id)

    if "file" not in request.GET or "function" not in request.GET:
        messages.error(request, "Missing argument")
        return redirect( reverse("browser.views.project_detail", args=(project.id,)))

    files = project.file_set.filter( name=request.GET["file"] )
    if len(files) < 1 :
        messages.error(request, "Cannot find %s in project" % request.GET["file"])
        return redirect( reverse("browser.views.project_detail", args=(project.id,)))

    if not files[0].is_parsed and not project.is_parsed:
        messages.error(request, "Project must be xref-ed first")
        return redirect( reverse("browser.views.project_detail", args=(project.id,)))
    
    callers = Function.objects.filter(project=project,
                                      name=request.GET["function"],
                                      file=files[0])

    if callers.count() == 0:
        messages.error(request, "No function matching criterias")
        return redirect( reverse("browser.views.project_detail", args=(project.id,)))
            
    elif callers.count() > 1:
        messages.error(request, "More than one function match criterias")
        return redirect( reverse("browser.views.project_detail", args=(project.id,)))

    caller_f = callers[0]

    try :
        depth = int(request.GET.get('depth', -1))
    except ValueError:
        depth = -1

    # xref_to = request.GET.get("xref", True)
    # xref_to = False if request.GET.get('xref')=='1' else True

    if request.GET.get('xref', '1')=='1':
        xref_to = True
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id, "up", depth)
    else:
        xref_to = True
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id, "down", depth)
        
    
    basename = hashlib.sha256(base).hexdigest() + ".svg"
    pic_name = unipath.Path(settings.CACHE_PATH + "/" + basename).absolute()

    if not pic_name.isfile():
        # if no file in cache, create it
        ret, err = generate_graph(pic_name, project, caller_f, xref_to, depth)
        if ret==False :
            messages.error(request, "Failed to create png graph: %s" % err)
            return redirect( reverse("browser.views.project_detail", args=(project.id,)))

    return redirect(reverse("browser.views.get_cache", args=(basename,)))
Example #3
0
def project_draw(request, project_id):
    """
    
    """
    valid_method_or_404(request, [
        "GET",
    ])

    project = get_object_or_404(Project, pk=project_id)

    if "file" not in request.GET or "function" not in request.GET:
        messages.error(request, "Missing argument")
        return redirect(
            reverse("browser.views.project_detail", args=(project.id, )))

    files = project.file_set.filter(name=request.GET["file"])
    if len(files) < 1:
        messages.error(request,
                       "Cannot find %s in project" % request.GET["file"])
        return redirect(
            reverse("browser.views.project_detail", args=(project.id, )))

    if not files[0].is_parsed and not project.is_parsed:
        messages.error(request, "Project must be xref-ed first")
        return redirect(
            reverse("browser.views.project_detail", args=(project.id, )))

    callers = Function.objects.filter(project=project,
                                      name=request.GET["function"],
                                      file=files[0])

    if callers.count() == 0:
        messages.error(request, "No function matching criterias")
        return redirect(
            reverse("browser.views.project_detail", args=(project.id, )))

    elif callers.count() > 1:
        messages.error(request, "More than one function match criterias")
        return redirect(
            reverse("browser.views.project_detail", args=(project.id, )))

    caller_f = callers[0]

    try:
        depth = int(request.GET.get('depth', -1))
    except ValueError:
        depth = -1

    # xref_to = request.GET.get("xref", True)
    # xref_to = False if request.GET.get('xref')=='1' else True

    if request.GET.get('xref', '1') == '1':
        xref_to = True
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id,
                                          "up", depth)
    else:
        xref_to = True
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id,
                                          "down", depth)

    basename = hashlib.sha256(base).hexdigest() + ".svg"
    pic_name = unipath.Path(settings.CACHE_PATH + "/" + basename).absolute()

    if not pic_name.isfile():
        # if no file in cache, create it
        ret, err = generate_graph(pic_name, project, caller_f, xref_to, depth)
        if ret == False:
            messages.error(request, "Failed to create png graph: %s" % err)
            return redirect(
                reverse("browser.views.project_detail", args=(project.id, )))

    return redirect(reverse("browser.views.get_cache", args=(basename, )))
Example #4
0
def ajax_add_funcgraph_link(request, f, d, x):
    """
    
    """
    valid_method_or_404(request, [
        "POST",
    ])
    dajax = Dajax()

    try:
        depth = int(d)
    except ValueError:
        depth = -1
    xref = x if x is not None else True

    try:
        for obj in serializers.deserialize("xml", f):
            data = obj
            data.save()
            break

        caller_f = data.object

        if not isinstance(caller_f, Function):
            return dajax.json()

        project = caller_f.project

        if not project.is_parsed:
            return dajax.json()

    except xml.sax.SAXParseException:
        return dajax.json()

    project = caller_f.project
    if f:
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id,
                                          "up", depth)
    else:
        base = settings.CACHED_SVG_FMT % (project.id, caller_f.id, caller_f.id,
                                          "down", depth)
    hashed_basename = hashlib.sha256(base).hexdigest() + ".svg"
    pic_name = unipath.Path(settings.CACHE_PATH + "/" + hashed_basename)

    if not pic_name.isfile():
        ret, err = generate_graph(pic_name, project, caller_f, xref, depth)
        if ret == False:
            return dajax.json()

    fmt_str = "<tr>"
    fmt_str += "<td width=\"40%\">{0}</td>"
    fmt_str += "<td width=\"15%\">{1}</td>"
    fmt_str += "<td width=\"15%\">{2}</td>"
    fmt_str += "<td width=\"30%\"><a href=\"{3}\">{0}</a></td>"
    fmt_str += "</tr>"

    line = fmt_str.format(
        caller_f.name, xref, depth,
        reverse('browser.views.get_cache', args=(hashed_basename, )))
    dajax.assign('#table-graphs', 'innerHTML', line)
    return dajax.json()