ore.management.commands.gmlimport.Command.handle()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 15
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 15
rs 9.65
c 0
b 0
f 0
cc 2
nop 3
1
from django.core.management.base import BaseCommand
2
from ore.models import Graph, Project
3
from django.contrib.auth.models import User
4
5
6
class Command(BaseCommand):
7
    args = '<user_name> <type> <graph_file>'
8
    help = 'Imports the given GraphML as new graph'
9
10
    def handle(self, *args, **options):
11
        try:
12
            user = User.objects.get(username=args[0])
13
        except Exception:
14
            print "Unknown user, try one of these:"
15
            print User.objects.all()
16
            exit(1)
17
        assert(args[1] in ('faulttree', 'fuzztree'))
18
        project = Project(owner=user, name="Imported graph")
19
        project.save()
20
        graph = Graph(owner=user, kind=args[1], project=project)
21
        graph.save()
22
        xmldata = open(args[2]).read()
23
        graph.from_graphml(xmldata)
24
        print "Graph created, ID is %u" % graph.pk
25