Revision df456124 snf-astakos-app/astakos/im/management/commands/service-add.py
b/snf-astakos-app/astakos/im/management/commands/service-add.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from optparse import make_option |
35 |
import string |
|
35 | 36 |
|
36 | 37 |
from django.core.management.base import BaseCommand, CommandError |
37 | 38 |
from django.db.utils import IntegrityError |
... | ... | |
47 | 48 |
make_option('--type', |
48 | 49 |
dest='type', |
49 | 50 |
help="Service type"), |
51 |
make_option('-f', '--no-confirm', |
|
52 |
action='store_true', |
|
53 |
default=False, |
|
54 |
dest='force', |
|
55 |
help="Do not ask for confirmation"), |
|
50 | 56 |
) |
51 | 57 |
|
52 | 58 |
def handle(self, *args, **options): |
... | ... | |
57 | 63 |
url = args[1] |
58 | 64 |
api_url = args[2] |
59 | 65 |
kwargs = dict(name=name, url=url, api_url=api_url) |
60 |
if options['type']: |
|
61 |
kwargs['type'] = options['type'] |
|
66 |
s_type = options['type'] |
|
67 |
if s_type: |
|
68 |
kwargs['type'] = s_type |
|
62 | 69 |
|
63 | 70 |
try: |
64 | 71 |
s = Service.objects.get(name=name) |
... | ... | |
77 | 84 |
m = "API URL '%s' is registered for another service." % api_url |
78 | 85 |
raise CommandError(m) |
79 | 86 |
|
87 |
force = options['force'] |
|
88 |
if not force: |
|
89 |
tp = (' of type %s' % s_type) if s_type else '' |
|
90 |
self.stdout.write("Add service %s%s with:\n" % (name, tp)) |
|
91 |
self.stdout.write("service URL: %s\n" % url) |
|
92 |
self.stdout.write("API URL: %s\n" % api_url) |
|
93 |
self.stdout.write("Confirm? (y/n) ") |
|
94 |
response = raw_input() |
|
95 |
if string.lower(response) not in ['y', 'yes']: |
|
96 |
self.stdout.write("Aborted.\n") |
|
97 |
return |
|
98 |
|
|
80 | 99 |
try: |
81 | 100 |
s = Service.objects.create(**kwargs) |
82 | 101 |
except BaseException: |
Also available in: Unified diff