Revision eb765213 snf-astakos-app/astakos/im/management/commands/component-add.py

b/snf-astakos-app/astakos/im/management/commands/component-add.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from optparse import make_option
34 35
from django.core.management.base import BaseCommand, CommandError
35 36
from astakos.im.models import Component
36 37

  
37 38

  
38 39
class Command(BaseCommand):
39
    args = "<name> <component URL>"
40
    args = "<name>"
40 41
    help = "Register a component"
41 42

  
43
    option_list = BaseCommand.option_list + (
44
        make_option('--ui-url',
45
                    dest='ui_url',
46
                    default=None,
47
                    help="Set UI URL"),
48
        make_option('--base-url',
49
                    dest='base_url',
50
                    default=None,
51
                    help="Set base URL"),
52
    )
53

  
42 54
    def handle(self, *args, **options):
43
        if len(args) < 2:
55
        if len(args) != 1:
44 56
            raise CommandError("Invalid number of arguments")
45 57

  
46 58
        name = args[0]
47
        url = args[1]
59
        base_url = options['base_url']
60
        ui_url = options['ui_url']
61

  
48 62
        try:
49
            s = Component.objects.get(name=name)
63
            Component.objects.get(name=name)
50 64
            m = "There already exists a component named '%s'." % name
51 65
            raise CommandError(m)
52 66
        except Component.DoesNotExist:
53 67
            pass
54 68

  
55
        components = list(Component.objects.filter(url=url))
56
        if components:
57
            m = "Component URL '%s' is registered for another service." % url
58
            raise CommandError(m)
59

  
60 69
        try:
61
            c = Component.objects.create(name=name, url=url)
70
            c = Component.objects.create(
71
                name=name, url=ui_url, base_url=base_url)
62 72
        except BaseException:
63 73
            raise CommandError("Failed to register component.")
64 74
        else:

Also available in: Unified diff