Commit 07ce94ba authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

fix graph view

parent d002e0ea
Pipeline #915 failed with stages
in 6 minutes and 47 seconds
......@@ -8,6 +8,7 @@
{% block navbarleft %}
<li class="nav-item"><a class="nav-link" href="{% url 'rainboard:forges' %}">Forges</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'rainboard:namespaces' %}">Namespaces</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'rainboard:graph' %}">Graph</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'rainboard:contributors' %}">Contributors</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'rainboard:gepetto' %}">Gepetto</a></li>
{% endblock %}
......
{% extends 'base.html' %}
{% block content %}
<h1>Graph</h1>
<img src="{% url 'rainboard:graph_svg' %}" alt="graph" />
{% endblock %}
from django.urls import path
from django.views.generic import RedirectView
from django.views.generic import RedirectView, TemplateView
from . import views
......@@ -19,4 +19,6 @@ urlpatterns = [
path('project/<str:slug>/.gitlab-ci.yml', views.ProjectGitlabView.as_view(), name='project-gitlab'),
path('doc', views.json_doc, name='doc'),
path('docker', views.docker, name='docker'),
path('graph.svg', views.graph_svg, name='graph_svg'),
path('graph', TemplateView.as_view(template_name='rainboard/graph.html'), name='graph'),
]
from subprocess import PIPE, run
from django.http.response import HttpResponse, JsonResponse
from django.views.generic import DetailView
......@@ -108,13 +110,13 @@ def docker(request):
def graph(request):
def graph_svg(request):
with open('/tmp/graph', 'w') as f:
print('digraph {', file=f)
for project in Project.objects.all():
for project in models.Project.objects.all():
print(f'{{I{project.pk} [label="{project}"];}}', file=f)
for dep in Dependency.objects.all():
for dep in models.Dependency.objects.all():
print(f'I{dep.project.pk} -> I{dep.library.pk};', file=f)
print('}', file=f)
svg = run(['dot', '/tmp/graph', '-Tsvg'], capture_output=True).stdout.decode()
svg = run(['dot', '/tmp/graph', '-Tsvg'], stdout=PIPE).stdout.decode()
return HttpResponse(svg, content_type='image/svg+xml')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment