Revision 66c90acd
b/snf-astakos-app/astakos/im/management/commands/group-add.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
from random import choice |
|
36 |
from string import digits, lowercase, uppercase |
|
37 |
from uuid import uuid4 |
|
38 |
from time import time |
|
39 |
from os.path import abspath |
|
40 |
|
|
41 |
from django.core.management.base import BaseCommand, CommandError |
|
42 |
from django.contrib.auth.models import Group |
|
43 |
|
|
44 |
from ._common import add_group_permission |
|
45 |
|
|
46 |
class Command(BaseCommand): |
|
47 |
args = "<groupname> [<permission> ...]" |
|
48 |
help = "Insert group" |
|
49 |
|
|
50 |
def handle(self, *args, **options): |
|
51 |
if len(args) < 1: |
|
52 |
raise CommandError("Invalid number of arguments") |
|
53 |
|
|
54 |
name = args[0].decode('utf8') |
|
55 |
|
|
56 |
try: |
|
57 |
Group.objects.get(name=name) |
|
58 |
raise CommandError("A group with this name already exists") |
|
59 |
except Group.DoesNotExist, e: |
|
60 |
group = Group(name=name) |
|
61 |
group.save() |
|
62 |
msg = "Created group id %d" % (group.id,) |
|
63 |
self.stdout.write(msg + '\n') |
|
64 |
try: |
|
65 |
for pname in args[1:]: |
|
66 |
r, created = add_group_permission(group, pname) |
|
67 |
if created: |
|
68 |
self.stdout.write('Permission: %s created successfully\n' % pname) |
|
69 |
if r == 0: |
|
70 |
self.stdout.write('Group has already permission: %s\n' % pname) |
|
71 |
else: |
|
72 |
self.stdout.write('Permission: %s added successfully\n' % pname) |
|
73 |
except Exception, e: |
|
74 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/management/commands/group-list.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group |
|
38 |
|
|
39 |
from astakos.im.models import AstakosUser |
|
40 |
|
|
41 |
from ._common import format_bool |
|
42 |
|
|
43 |
|
|
44 |
class Command(BaseCommand): |
|
45 |
help = "List g" |
|
46 |
|
|
47 |
option_list = BaseCommand.option_list + ( |
|
48 |
make_option('-c', |
|
49 |
action='store_true', |
|
50 |
dest='csv', |
|
51 |
default=False, |
|
52 |
help="Use pipes to separate values"), |
|
53 |
) |
|
54 |
|
|
55 |
def handle(self, *args, **options): |
|
56 |
if args: |
|
57 |
raise CommandError("Command doesn't accept any arguments") |
|
58 |
|
|
59 |
groups = Group.objects.all() |
|
60 |
|
|
61 |
labels = ('id', 'name', 'permissions') |
|
62 |
columns = (3, 12, 50) |
|
63 |
|
|
64 |
if not options['csv']: |
|
65 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
66 |
self.stdout.write(line + '\n') |
|
67 |
sep = '-' * len(line) |
|
68 |
self.stdout.write(sep + '\n') |
|
69 |
|
|
70 |
for group in groups: |
|
71 |
fields = (str(group.id), group.name, |
|
72 |
','.join(p.codename for p in group.permissions.all())) |
|
73 |
|
|
74 |
if options['csv']: |
|
75 |
line = '|'.join(fields) |
|
76 |
else: |
|
77 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
78 |
|
|
79 |
self.stdout.write(line.encode('utf8') + '\n') |
b/snf-astakos-app/astakos/im/management/commands/group-permissions-add.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group, Permission |
|
38 |
from django.contrib.contenttypes.models import ContentType |
|
39 |
from django.core.exceptions import ValidationError |
|
40 |
|
|
41 |
from astakos.im.models import AstakosUser |
|
42 |
from ._common import add_group_permission |
|
43 |
|
|
44 |
class Command(BaseCommand): |
|
45 |
args = "<groupname> <permission> [<permissions> ...]" |
|
46 |
help = "Add group permissions" |
|
47 |
|
|
48 |
def handle(self, *args, **options): |
|
49 |
if len(args) < 2: |
|
50 |
raise CommandError("Please provide a group name and at least one permission") |
|
51 |
|
|
52 |
group = None |
|
53 |
try: |
|
54 |
if args[0].isdigit(): |
|
55 |
group = Group.objects.get(id=args[0]) |
|
56 |
else: |
|
57 |
group = Group.objects.get(name=args[0]) |
|
58 |
except Group.DoesNotExist, e: |
|
59 |
raise CommandError("Invalid group") |
|
60 |
|
|
61 |
try: |
|
62 |
content_type = ContentType.objects.get(app_label='im', |
|
63 |
model='astakosuser') |
|
64 |
for pname in args[1:]: |
|
65 |
r, created = add_group_permission(group, pname) |
|
66 |
if created: |
|
67 |
self.stdout.write('Permission: %s created successfully\n' % pname) |
|
68 |
if r == 0: |
|
69 |
self.stdout.write('Group has already permission: %s\n' % pname) |
|
70 |
else: |
|
71 |
self.stdout.write('Permission: %s added successfully\n' % pname) |
|
72 |
except Exception, e: |
|
73 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/management/commands/group-permissions-remove.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group |
|
38 |
from django.core.exceptions import ValidationError |
|
39 |
|
|
40 |
from astakos.im.models import AstakosUser |
|
41 |
from ._common import remove_group_permission |
|
42 |
|
|
43 |
class Command(BaseCommand): |
|
44 |
args = "<groupname> <permission> [<permissions> ...]" |
|
45 |
help = "Remove group permissions" |
|
46 |
|
|
47 |
def handle(self, *args, **options): |
|
48 |
if len(args) < 2: |
|
49 |
raise CommandError("Please provide a group name and at least one permission") |
|
50 |
|
|
51 |
group = None |
|
52 |
try: |
|
53 |
if args[0].isdigit(): |
|
54 |
group = Group.objects.get(id=args[0]) |
|
55 |
else: |
|
56 |
group = Group.objects.get(name=args[0]) |
|
57 |
except Group.DoesNotExist, e: |
|
58 |
raise CommandError("Invalid group") |
|
59 |
|
|
60 |
try: |
|
61 |
for pname in args[1:]: |
|
62 |
r = remove_group_permission(group, pname) |
|
63 |
if r < 0: |
|
64 |
self.stdout.write('Invalid permission codename: %s\n' % pname) |
|
65 |
elif r == 0: |
|
66 |
self.stdout.write('Group has not permission: %s\n' % pname) |
|
67 |
elif r > 0: |
|
68 |
self.stdout.write('Permission: %s removed successfully\n' % pname) |
|
69 |
except Exception, e: |
|
70 |
raise CommandError(e) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
from random import choice |
|
36 |
from string import digits, lowercase, uppercase |
|
37 |
from uuid import uuid4 |
|
38 |
from time import time |
|
39 |
from os.path import abspath |
|
40 |
|
|
41 |
from django.core.management.base import BaseCommand, CommandError |
|
42 |
from django.contrib.auth.models import Group |
|
43 |
|
|
44 |
from ._common import add_group_permission |
|
45 |
|
|
46 |
class Command(BaseCommand): |
|
47 |
args = "<groupname> [<permission> ...]" |
|
48 |
help = "Insert group" |
|
49 |
|
|
50 |
def handle(self, *args, **options): |
|
51 |
if len(args) < 1: |
|
52 |
raise CommandError("Invalid number of arguments") |
|
53 |
|
|
54 |
name = args[0].decode('utf8') |
|
55 |
|
|
56 |
try: |
|
57 |
Group.objects.get(name=name) |
|
58 |
raise CommandError("A group with this name already exists") |
|
59 |
except Group.DoesNotExist, e: |
|
60 |
group = Group(name=name) |
|
61 |
group.save() |
|
62 |
msg = "Created group id %d" % (group.id,) |
|
63 |
self.stdout.write(msg + '\n') |
|
64 |
try: |
|
65 |
for pname in args[1:]: |
|
66 |
r, created = add_group_permission(group, pname) |
|
67 |
if created: |
|
68 |
self.stdout.write('Permission: %s created successfully\n' % pname) |
|
69 |
if r == 0: |
|
70 |
self.stdout.write('Group has already permission: %s\n' % pname) |
|
71 |
else: |
|
72 |
self.stdout.write('Permission: %s added successfully\n' % pname) |
|
73 |
except Exception, e: |
|
74 |
raise CommandError(e) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group, Permission |
|
38 |
from django.contrib.contenttypes.models import ContentType |
|
39 |
from django.core.exceptions import ValidationError |
|
40 |
|
|
41 |
from astakos.im.models import AstakosUser |
|
42 |
from ._common import add_group_permission |
|
43 |
|
|
44 |
class Command(BaseCommand): |
|
45 |
args = "<groupname> <permission> [<permissions> ...]" |
|
46 |
help = "Add group permissions" |
|
47 |
|
|
48 |
def handle(self, *args, **options): |
|
49 |
if len(args) < 2: |
|
50 |
raise CommandError("Please provide a group name and at least one permission") |
|
51 |
|
|
52 |
group = None |
|
53 |
try: |
|
54 |
if args[0].isdigit(): |
|
55 |
group = Group.objects.get(id=args[0]) |
|
56 |
else: |
|
57 |
group = Group.objects.get(name=args[0]) |
|
58 |
except Group.DoesNotExist, e: |
|
59 |
raise CommandError("Invalid group") |
|
60 |
|
|
61 |
try: |
|
62 |
content_type = ContentType.objects.get(app_label='im', |
|
63 |
model='astakosuser') |
|
64 |
for pname in args[1:]: |
|
65 |
r, created = add_group_permission(group, pname) |
|
66 |
if created: |
|
67 |
self.stdout.write('Permission: %s created successfully\n' % pname) |
|
68 |
if r == 0: |
|
69 |
self.stdout.write('Group has already permission: %s\n' % pname) |
|
70 |
else: |
|
71 |
self.stdout.write('Permission: %s added successfully\n' % pname) |
|
72 |
except Exception, e: |
|
73 |
raise CommandError(e) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group |
|
38 |
|
|
39 |
from astakos.im.models import AstakosUser |
|
40 |
|
|
41 |
from ._common import format_bool |
|
42 |
|
|
43 |
|
|
44 |
class Command(BaseCommand): |
|
45 |
help = "List g" |
|
46 |
|
|
47 |
option_list = BaseCommand.option_list + ( |
|
48 |
make_option('-c', |
|
49 |
action='store_true', |
|
50 |
dest='csv', |
|
51 |
default=False, |
|
52 |
help="Use pipes to separate values"), |
|
53 |
) |
|
54 |
|
|
55 |
def handle(self, *args, **options): |
|
56 |
if args: |
|
57 |
raise CommandError("Command doesn't accept any arguments") |
|
58 |
|
|
59 |
groups = Group.objects.all() |
|
60 |
|
|
61 |
labels = ('id', 'name', 'permissions') |
|
62 |
columns = (3, 12, 50) |
|
63 |
|
|
64 |
if not options['csv']: |
|
65 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
66 |
self.stdout.write(line + '\n') |
|
67 |
sep = '-' * len(line) |
|
68 |
self.stdout.write(sep + '\n') |
|
69 |
|
|
70 |
for group in groups: |
|
71 |
fields = (str(group.id), group.name, |
|
72 |
','.join(p.codename for p in group.permissions.all())) |
|
73 |
|
|
74 |
if options['csv']: |
|
75 |
line = '|'.join(fields) |
|
76 |
else: |
|
77 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
78 |
|
|
79 |
self.stdout.write(line.encode('utf8') + '\n') |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
from django.contrib.auth.models import Group |
|
38 |
from django.core.exceptions import ValidationError |
|
39 |
|
|
40 |
from astakos.im.models import AstakosUser |
|
41 |
from ._common import remove_group_permission |
|
42 |
|
|
43 |
class Command(BaseCommand): |
|
44 |
args = "<groupname> <permission> [<permissions> ...]" |
|
45 |
help = "Remove group permissions" |
|
46 |
|
|
47 |
def handle(self, *args, **options): |
|
48 |
if len(args) < 2: |
|
49 |
raise CommandError("Please provide a group name and at least one permission") |
|
50 |
|
|
51 |
group = None |
|
52 |
try: |
|
53 |
if args[0].isdigit(): |
|
54 |
group = Group.objects.get(id=args[0]) |
|
55 |
else: |
|
56 |
group = Group.objects.get(name=args[0]) |
|
57 |
except Group.DoesNotExist, e: |
|
58 |
raise CommandError("Invalid group") |
|
59 |
|
|
60 |
try: |
|
61 |
for pname in args[1:]: |
|
62 |
r = remove_group_permission(group, pname) |
|
63 |
if r < 0: |
|
64 |
self.stdout.write('Invalid permission codename: %s\n' % pname) |
|
65 |
elif r == 0: |
|
66 |
self.stdout.write('Group has not permission: %s\n' % pname) |
|
67 |
elif r > 0: |
|
68 |
self.stdout.write('Permission: %s removed successfully\n' % pname) |
|
69 |
except Exception, e: |
|
70 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/management/commands/invitation-list.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
|
|
38 |
from astakos.im.models import Invitation |
|
39 |
|
|
40 |
from ._common import format_bool |
|
41 |
|
|
42 |
|
|
43 |
class Command(BaseCommand): |
|
44 |
help = "List invitations" |
|
45 |
|
|
46 |
option_list = BaseCommand.option_list + ( |
|
47 |
make_option('-c', |
|
48 |
action='store_true', |
|
49 |
dest='csv', |
|
50 |
default=False, |
|
51 |
help="Use pipes to separate values"), |
|
52 |
) |
|
53 |
|
|
54 |
def handle(self, *args, **options): |
|
55 |
if args: |
|
56 |
raise CommandError("Command doesn't accept any arguments") |
|
57 |
|
|
58 |
invitations = Invitation.objects.all() |
|
59 |
|
|
60 |
labels = ('id', 'inviter', 'email', 'real name', 'code', 'consumed') |
|
61 |
columns = (3, 24, 24, 24, 20, 4, 8) |
|
62 |
|
|
63 |
if not options['csv']: |
|
64 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
65 |
self.stdout.write(line + '\n') |
|
66 |
sep = '-' * len(line) |
|
67 |
self.stdout.write(sep + '\n') |
|
68 |
|
|
69 |
for invitation in invitations: |
|
70 |
id = str(invitation.id) |
|
71 |
code = str(invitation.code) |
|
72 |
consumed = format_bool(invitation.is_consumed) |
|
73 |
fields = (id, invitation.inviter.email, invitation.username, invitation.realname, |
|
74 |
code, consumed) |
|
75 |
|
|
76 |
if options['csv']: |
|
77 |
line = '|'.join(fields) |
|
78 |
else: |
|
79 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
80 |
|
|
81 |
self.stdout.write(line.encode('utf8') + '\n') |
b/snf-astakos-app/astakos/im/management/commands/invitation-show.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Invitation |
|
37 |
|
|
38 |
from ._common import format_bool, format_date |
|
39 |
|
|
40 |
|
|
41 |
class Command(BaseCommand): |
|
42 |
args = "<invitation ID>" |
|
43 |
help = "Show invitation info" |
|
44 |
|
|
45 |
def handle(self, *args, **options): |
|
46 |
if len(args) != 1: |
|
47 |
raise CommandError("Please provide an invitation id") |
|
48 |
|
|
49 |
try: |
|
50 |
invitation = Invitation.objects.get(id=int(args[0])) |
|
51 |
except Invitation.DoesNotExist: |
|
52 |
raise CommandError("Unknown invitation id '%s'" % (args[0],)) |
|
53 |
|
|
54 |
kv = { |
|
55 |
'id': invitation.id, |
|
56 |
'real name': invitation.realname, |
|
57 |
'email': invitation.username, |
|
58 |
'code': invitation.code, |
|
59 |
'consumed': format_bool(invitation.is_consumed), |
|
60 |
'date created': format_date(invitation.created), |
|
61 |
'date consumed': format_date(invitation.consumed), |
|
62 |
'inviter real name': invitation.inviter.realname, |
|
63 |
'invitater email': invitation.inviter.email, |
|
64 |
} |
|
65 |
|
|
66 |
for key, val in sorted(kv.items()): |
|
67 |
line = '%s: %s\n' % (key.rjust(18), val) |
|
68 |
self.stdout.write(line.encode('utf8')) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
|
|
38 |
from astakos.im.models import Invitation |
|
39 |
|
|
40 |
from ._common import format_bool |
|
41 |
|
|
42 |
|
|
43 |
class Command(BaseCommand): |
|
44 |
help = "List invitations" |
|
45 |
|
|
46 |
option_list = BaseCommand.option_list + ( |
|
47 |
make_option('-c', |
|
48 |
action='store_true', |
|
49 |
dest='csv', |
|
50 |
default=False, |
|
51 |
help="Use pipes to separate values"), |
|
52 |
) |
|
53 |
|
|
54 |
def handle(self, *args, **options): |
|
55 |
if args: |
|
56 |
raise CommandError("Command doesn't accept any arguments") |
|
57 |
|
|
58 |
invitations = Invitation.objects.all() |
|
59 |
|
|
60 |
labels = ('id', 'inviter', 'email', 'real name', 'code', 'consumed') |
|
61 |
columns = (3, 24, 24, 24, 20, 4, 8) |
|
62 |
|
|
63 |
if not options['csv']: |
|
64 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
65 |
self.stdout.write(line + '\n') |
|
66 |
sep = '-' * len(line) |
|
67 |
self.stdout.write(sep + '\n') |
|
68 |
|
|
69 |
for invitation in invitations: |
|
70 |
id = str(invitation.id) |
|
71 |
code = str(invitation.code) |
|
72 |
consumed = format_bool(invitation.is_consumed) |
|
73 |
fields = (id, invitation.inviter.email, invitation.username, invitation.realname, |
|
74 |
code, consumed) |
|
75 |
|
|
76 |
if options['csv']: |
|
77 |
line = '|'.join(fields) |
|
78 |
else: |
|
79 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
80 |
|
|
81 |
self.stdout.write(line.encode('utf8') + '\n') |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Invitation |
|
37 |
|
|
38 |
from ._common import format_bool, format_date |
|
39 |
|
|
40 |
|
|
41 |
class Command(BaseCommand): |
|
42 |
args = "<invitation ID>" |
|
43 |
help = "Show invitation info" |
|
44 |
|
|
45 |
def handle(self, *args, **options): |
|
46 |
if len(args) != 1: |
|
47 |
raise CommandError("Please provide an invitation id") |
|
48 |
|
|
49 |
try: |
|
50 |
invitation = Invitation.objects.get(id=int(args[0])) |
|
51 |
except Invitation.DoesNotExist: |
|
52 |
raise CommandError("Unknown invitation id '%s'" % (args[0],)) |
|
53 |
|
|
54 |
kv = { |
|
55 |
'id': invitation.id, |
|
56 |
'real name': invitation.realname, |
|
57 |
'email': invitation.username, |
|
58 |
'code': invitation.code, |
|
59 |
'consumed': format_bool(invitation.is_consumed), |
|
60 |
'date created': format_date(invitation.created), |
|
61 |
'date consumed': format_date(invitation.consumed), |
|
62 |
'inviter real name': invitation.inviter.realname, |
|
63 |
'invitater email': invitation.inviter.email, |
|
64 |
} |
|
65 |
|
|
66 |
for key, val in sorted(kv.items()): |
|
67 |
line = '%s: %s\n' % (key.rjust(18), val) |
|
68 |
self.stdout.write(line.encode('utf8')) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.functions import send_activation, SendMailError |
|
37 |
|
|
38 |
from ._common import get_user |
|
39 |
|
|
40 |
class Command(BaseCommand): |
|
41 |
args = "<user ID or email> [user ID or email] ..." |
|
42 |
help = "Sends an activation email to one or more users" |
|
43 |
|
|
44 |
def handle(self, *args, **options): |
|
45 |
if not args: |
|
46 |
raise CommandError("No user was given") |
|
47 |
|
|
48 |
for email_or_id in args: |
|
49 |
user = get_user(email_or_id, is_active=False) |
|
50 |
if not user: |
|
51 |
self.stderr.write("Unknown user '%s'\n" % (email_or_id,)) |
|
52 |
continue |
|
53 |
if user.is_active: |
|
54 |
self.stderr.write("Already active user '%s'\n" % (email_or_id,)) |
|
55 |
continue |
|
56 |
|
|
57 |
try: |
|
58 |
send_activation(user) |
|
59 |
except SendMailError, e: |
|
60 |
raise CommandError(e.message) |
|
61 |
|
|
62 |
self.stdout.write("Activation sent to '%s'\n" % (user.email,)) |
b/snf-astakos-app/astakos/im/management/commands/service-add.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Service |
|
37 |
|
|
38 |
class Command(BaseCommand): |
|
39 |
args = "<name> <url> [<icon>]" |
|
40 |
help = "Register a service" |
|
41 |
|
|
42 |
def handle(self, *args, **options): |
|
43 |
if len(args) < 2: |
|
44 |
raise CommandError("Invalid number of arguments") |
|
45 |
|
|
46 |
service = Service(name=args[0], url=args[1]) |
|
47 |
if len(args) == 3: |
|
48 |
service.icon = args[2] |
|
49 |
try: |
|
50 |
service.save() |
|
51 |
self.stdout.write('Service created with token: %s\n' % service.auth_token) |
|
52 |
except Exception, e: |
|
53 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/management/commands/service-list.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
|
|
38 |
from astakos.im.models import Service |
|
39 |
|
|
40 |
class Command(BaseCommand): |
|
41 |
help = "List g" |
|
42 |
|
|
43 |
option_list = BaseCommand.option_list + ( |
|
44 |
make_option('-c', |
|
45 |
action='store_true', |
|
46 |
dest='csv', |
|
47 |
default=False, |
|
48 |
help="Use pipes to separate values"), |
|
49 |
) |
|
50 |
|
|
51 |
def handle(self, *args, **options): |
|
52 |
if args: |
|
53 |
raise CommandError("Command doesn't accept any arguments") |
|
54 |
|
|
55 |
services = Service.objects.all() |
|
56 |
|
|
57 |
labels = ('id', 'name', 'url', 'auth_token', 'icon') |
|
58 |
columns = (3, 12, 40, 20, 20) |
|
59 |
|
|
60 |
if not options['csv']: |
|
61 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
62 |
self.stdout.write(line + '\n') |
|
63 |
sep = '-' * len(line) |
|
64 |
self.stdout.write(sep + '\n') |
|
65 |
|
|
66 |
for service in services: |
|
67 |
fields = (str(service.id), service.name, service.url, |
|
68 |
service.auth_token, |
|
69 |
service.icon) |
|
70 |
|
|
71 |
if options['csv']: |
|
72 |
line = '|'.join(fields) |
|
73 |
else: |
|
74 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
75 |
|
|
76 |
self.stdout.write(line.encode('utf8') + '\n') |
b/snf-astakos-app/astakos/im/management/commands/service-remove.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Service |
|
37 |
|
|
38 |
class Command(BaseCommand): |
|
39 |
args = "<name>" |
|
40 |
help = "Unregister a service" |
|
41 |
|
|
42 |
def handle(self, *args, **options): |
|
43 |
if len(args) < 1: |
|
44 |
raise CommandError("Invalid number of arguments") |
|
45 |
|
|
46 |
try: |
|
47 |
service = Service.objects.get(name=args[0]) |
|
48 |
service.delete() |
|
49 |
except Service.DoesNotExist, e: |
|
50 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/management/commands/service-token-renew.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Service |
|
37 |
|
|
38 |
class Command(BaseCommand): |
|
39 |
args = "<name>" |
|
40 |
help = "Renew service token" |
|
41 |
|
|
42 |
def handle(self, *args, **options): |
|
43 |
if len(args) != 1: |
|
44 |
raise CommandError("Invalid number of arguments") |
|
45 |
|
|
46 |
try: |
|
47 |
service = Service.objects.get(name=args[0]) |
|
48 |
service.renew_token() |
|
49 |
service.save() |
|
50 |
self.stdout.write('New service token: %s\n' % service.auth_token) |
|
51 |
except Service.DoesNotExist: |
|
52 |
raise CommandError("Invalid service name") |
|
53 |
except Exception, e: |
|
54 |
raise CommandError(e) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Service |
|
37 |
|
|
38 |
class Command(BaseCommand): |
|
39 |
args = "<name> <url> [<icon>]" |
|
40 |
help = "Register a service" |
|
41 |
|
|
42 |
def handle(self, *args, **options): |
|
43 |
if len(args) < 2: |
|
44 |
raise CommandError("Invalid number of arguments") |
|
45 |
|
|
46 |
service = Service(name=args[0], url=args[1]) |
|
47 |
if len(args) == 3: |
|
48 |
service.icon = args[2] |
|
49 |
try: |
|
50 |
service.save() |
|
51 |
self.stdout.write('Service created with token: %s\n' % service.auth_token) |
|
52 |
except Exception, e: |
|
53 |
raise CommandError(e) |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from optparse import make_option |
|
35 |
|
|
36 |
from django.core.management.base import BaseCommand, CommandError |
|
37 |
|
|
38 |
from astakos.im.models import Service |
|
39 |
|
|
40 |
class Command(BaseCommand): |
|
41 |
help = "List g" |
|
42 |
|
|
43 |
option_list = BaseCommand.option_list + ( |
|
44 |
make_option('-c', |
|
45 |
action='store_true', |
|
46 |
dest='csv', |
|
47 |
default=False, |
|
48 |
help="Use pipes to separate values"), |
|
49 |
) |
|
50 |
|
|
51 |
def handle(self, *args, **options): |
|
52 |
if args: |
|
53 |
raise CommandError("Command doesn't accept any arguments") |
|
54 |
|
|
55 |
services = Service.objects.all() |
|
56 |
|
|
57 |
labels = ('id', 'name', 'url', 'auth_token', 'icon') |
|
58 |
columns = (3, 12, 40, 20, 20) |
|
59 |
|
|
60 |
if not options['csv']: |
|
61 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
62 |
self.stdout.write(line + '\n') |
|
63 |
sep = '-' * len(line) |
|
64 |
self.stdout.write(sep + '\n') |
|
65 |
|
|
66 |
for service in services: |
|
67 |
fields = (str(service.id), service.name, service.url, |
|
68 |
service.auth_token, |
|
69 |
service.icon) |
|
70 |
|
|
71 |
if options['csv']: |
|
72 |
line = '|'.join(fields) |
|
73 |
else: |
|
74 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
75 |
|
|
76 |
self.stdout.write(line.encode('utf8') + '\n') |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from django.core.management.base import BaseCommand, CommandError |
|
35 |
|
|
36 |
from astakos.im.models import Service |
|
37 |
|
|
38 |
class Command(BaseCommand): |
|
39 |
args = "<name>" |
|
40 |
help = "Unregister a service" |
|
41 |
|
|
42 |
def handle(self, *args, **options): |
|
43 |
if len(args) < 1: |
|
44 |
raise CommandError("Invalid number of arguments") |
|
45 |
|
|
46 |
try: |
|
47 |
service = Service.objects.get(name=args[0]) |
|
48 |
service.delete() |
|
49 |
except Service.DoesNotExist, e: |
|
50 |
raise CommandError(e) |
Also available in: Unified diff