Revision 6bdf0aa3

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 django.core.management.base import BaseCommand, CommandError
35

  
36
from astakos.im.models import AstakosGroup
37

  
38
from ._common import add_group_permission
39

  
40

  
41
class Command(BaseCommand):
42
    args = "<groupname> [<permission> ...]"
43
    help = "Insert group"
44

  
45
    def handle(self, *args, **options):
46
        if len(args) < 1:
47
            raise CommandError("Invalid number of arguments")
48

  
49
        name = args[0].decode('utf8')
50

  
51
        try:
52
            AstakosGroup.objects.get(name=name)
53
            raise CommandError("A group with this name already exists")
54
        except AstakosGroup.DoesNotExist, e:
55
            group = AstakosGroup(name=name)
56
            group.save()
57
            msg = "Created group id %d" % (group.id,)
58
            self.stdout.write(msg + '\n')
59
            try:
60
                for pname in args[1:]:
61
                    r, created = add_group_permission(group, pname)
62
                    if created:
63
                        self.stdout.write(
64
                            'Permission: %s created successfully\n' % pname)
65
                    if r == 0:
66
                        self.stdout.write(
67
                            'Group has already permission: %s\n' % pname)
68
                    else:
69
                        self.stdout.write(
70
                            'Permission: %s added successfully\n' % pname)
71
            except Exception, e:
72
                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

  
38
from astakos.im.models import AstakosGroup
39

  
40
from ._common import format_bool
41

  
42

  
43
class Command(BaseCommand):
44
    help = "List groups"
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
        make_option('-p',
53
                    action='store_true',
54
                    dest='pending',
55
                    default=False,
56
                    help="List only groups pending enable"),
57
    )
58

  
59
    def handle(self, *args, **options):
60
        groups = AstakosGroup.objects.all()
61

  
62
        if options.get('pending'):
63
            groups = filter(lambda g: g.is_disabled, groups)
64

  
65
        labels = ('id', 'name', 'enabled', 'moderation', 'permissions')
66
        columns = (3, 25, 12, 12, 50)
67

  
68
        if not options.get('csv'):
69
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
70
            self.stdout.write(line + '\n')
71
            sep = '-' * len(line)
72
            self.stdout.write(sep + '\n')
73

  
74
        for group in groups:
75
            fields = (str(group.id),
76
                      group.name,
77
                      format_bool(group.is_enabled),
78
                      format_bool(group.moderation_enabled),
79
                      ','.join(p.codename for p in group.permissions.all()))
80

  
81
            if options.get('csv'):
82
                line = '|'.join(fields)
83
            else:
84
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
85

  
86
            self.stdout.write(line.encode('utf8') + '\n')
b/snf-astakos-app/astakos/im/management/commands/group-update.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 AstakosGroup
39
from ._common import add_group_permission, remove_group_permission
40

  
41

  
42
class Command(BaseCommand):
43
    args = "<groupname>"
44
    help = "Update group"
45

  
46
    option_list = BaseCommand.option_list + (
47
        make_option('--add-permission',
48
                    dest='add-permission',
49
                    help="Add user permission"),
50
        make_option('--delete-permission',
51
                    dest='delete-permission',
52
                    help="Delete user permission"),
53
        make_option('--enable',
54
                    action='store_true',
55
                    dest='enable',
56
                    default=False,
57
                    help="Enable group"),
58
        make_option('--disable',
59
                    action='store_true',
60
                    dest='disable',
61
                    default=False,
62
                    help="Disable group"),
63
    )
64

  
65
    def handle(self, *args, **options):
66
        if len(args) < 1:
67
            raise CommandError("Please provide a group identifier")
68

  
69
        group = None
70
        try:
71
            if args[0].isdigit():
72
                group = AstakosGroup.objects.get(id=args[0])
73
            else:
74
                group = AstakosGroup.objects.get(name=args[0])
75
        except AstakosGroup.DoesNotExist, e:
76
            raise CommandError("Invalid group")
77

  
78
        try:
79
            pname = options.get('add-permission')
80
            if pname:
81
                r, created = add_group_permission(group, pname)
82
                if created:
83
                    self.stdout.write(
84
                        'Permission: %s created successfully\n' % pname)
85
                if r == 0:
86
                    self.stdout.write(
87
                        'Group has already permission: %s\n' % pname)
88
                else:
89
                    self.stdout.write(
90
                        'Permission: %s added successfully\n' % pname)
91

  
92
            pname = options.get('delete-permission')
93
            if pname:
94
                r = remove_group_permission(group, pname)
95
                if r < 0:
96
                    self.stdout.write(
97
                        'Invalid permission codename: %s\n' % pname)
98
                elif r == 0:
99
                    self.stdout.write('Group has not permission: %s\n' % pname)
100
                elif r > 0:
101
                    self.stdout.write(
102
                        'Permission: %s removed successfully\n' % pname)
103

  
104
            if options.get('enable'):
105
                group.enable()
106
            elif options.get('disable'):
107
                group.disable()
108

  
109
        except Exception, e:
110
            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 AstakosGroup
37

  
38
from ._common import add_group_permission
39

  
40

  
41
class Command(BaseCommand):
42
    args = "<groupname> [<permission> ...]"
43
    help = "Insert group"
44

  
45
    def handle(self, *args, **options):
46
        if len(args) < 1:
47
            raise CommandError("Invalid number of arguments")
48

  
49
        name = args[0].decode('utf8')
50

  
51
        try:
52
            AstakosGroup.objects.get(name=name)
53
            raise CommandError("A group with this name already exists")
54
        except AstakosGroup.DoesNotExist, e:
55
            group = AstakosGroup(name=name)
56
            group.save()
57
            msg = "Created group id %d" % (group.id,)
58
            self.stdout.write(msg + '\n')
59
            try:
60
                for pname in args[1:]:
61
                    r, created = add_group_permission(group, pname)
62
                    if created:
63
                        self.stdout.write(
64
                            'Permission: %s created successfully\n' % pname)
65
                    if r == 0:
66
                        self.stdout.write(
67
                            'Group has already permission: %s\n' % pname)
68
                    else:
69
                        self.stdout.write(
70
                            'Permission: %s added successfully\n' % pname)
71
            except Exception, e:
72
                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 AstakosGroup
39

  
40
from ._common import format_bool
41

  
42

  
43
class Command(BaseCommand):
44
    help = "List groups"
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
        make_option('-p',
53
                    action='store_true',
54
                    dest='pending',
55
                    default=False,
56
                    help="List only groups pending enable"),
57
    )
58

  
59
    def handle(self, *args, **options):
60
        groups = AstakosGroup.objects.all()
61

  
62
        if options.get('pending'):
63
            groups = filter(lambda g: g.is_disabled, groups)
64

  
65
        labels = ('id', 'name', 'enabled', 'moderation', 'permissions')
66
        columns = (3, 25, 12, 12, 50)
67

  
68
        if not options.get('csv'):
69
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
70
            self.stdout.write(line + '\n')
71
            sep = '-' * len(line)
72
            self.stdout.write(sep + '\n')
73

  
74
        for group in groups:
75
            fields = (str(group.id),
76
                      group.name,
77
                      format_bool(group.is_enabled),
78
                      format_bool(group.moderation_enabled),
79
                      ','.join(p.codename for p in group.permissions.all()))
80

  
81
            if options.get('csv'):
82
                line = '|'.join(fields)
83
            else:
84
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
85

  
86
            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

  
38
from astakos.im.models import AstakosGroup
39
from ._common import add_group_permission, remove_group_permission
40

  
41

  
42
class Command(BaseCommand):
43
    args = "<groupname>"
44
    help = "Update group"
45

  
46
    option_list = BaseCommand.option_list + (
47
        make_option('--add-permission',
48
                    dest='add-permission',
49
                    help="Add user permission"),
50
        make_option('--delete-permission',
51
                    dest='delete-permission',
52
                    help="Delete user permission"),
53
        make_option('--enable',
54
                    action='store_true',
55
                    dest='enable',
56
                    default=False,
57
                    help="Enable group"),
58
        make_option('--disable',
59
                    action='store_true',
60
                    dest='disable',
61
                    default=False,
62
                    help="Disable group"),
63
    )
64

  
65
    def handle(self, *args, **options):
66
        if len(args) < 1:
67
            raise CommandError("Please provide a group identifier")
68

  
69
        group = None
70
        try:
71
            if args[0].isdigit():
72
                group = AstakosGroup.objects.get(id=args[0])
73
            else:
74
                group = AstakosGroup.objects.get(name=args[0])
75
        except AstakosGroup.DoesNotExist, e:
76
            raise CommandError("Invalid group")
77

  
78
        try:
79
            pname = options.get('add-permission')
80
            if pname:
81
                r, created = add_group_permission(group, pname)
82
                if created:
83
                    self.stdout.write(
84
                        'Permission: %s created successfully\n' % pname)
85
                if r == 0:
86
                    self.stdout.write(
87
                        'Group has already permission: %s\n' % pname)
88
                else:
89
                    self.stdout.write(
90
                        'Permission: %s added successfully\n' % pname)
91

  
92
            pname = options.get('delete-permission')
93
            if pname:
94
                r = remove_group_permission(group, pname)
95
                if r < 0:
96
                    self.stdout.write(
97
                        'Invalid permission codename: %s\n' % pname)
98
                elif r == 0:
99
                    self.stdout.write('Group has not permission: %s\n' % pname)
100
                elif r > 0:
101
                    self.stdout.write(
102
                        'Permission: %s removed successfully\n' % pname)
103

  
104
            if options.get('enable'):
105
                group.enable()
106
            elif options.get('disable'):
107
                group.disable()
108

  
109
        except Exception, e:
110
            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 = (
74
                id, invitation.inviter.email, invitation.username, invitation.realname,
75
                code, consumed)
76

  
77
            if options['csv']:
78
                line = '|'.join(fields)
79
            else:
80
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
81

  
82
            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 = (
74
                id, invitation.inviter.email, invitation.username, invitation.realname,
75
                code, consumed)
76

  
77
            if options['csv']:
78
                line = '|'.join(fields)
79
            else:
80
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
81

  
82
            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'))
b/snf-astakos-app/astakos/im/management/commands/quotaholder-bootstrap.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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import AstakosUser, Resource
38
from astakos.im.endpoints.quotaholder import register_users, register_resources
39

  
40

  
41
class Command(BaseCommand):
42
    help = "Send user information and resource quota in the Quotaholder"
43

  
44
    def handle(self, *args, **options):
45
        try:
46
            register_resources(Resource.objects.all())
47
            register_users(AstakosUser.objects.all())
48
        except BaseException, e:
49
            raise CommandError("Bootstrap failed.")
/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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import AstakosUser, Resource
38
from astakos.im.endpoints.quotaholder import register_users, register_resources
39

  
40

  
41
class Command(BaseCommand):
42
    help = "Send user information and resource quota in the Quotaholder"
43

  
44
    def handle(self, *args, **options):
45
        try:
46
            register_resources(Resource.objects.all())
47
            register_users(AstakosUser.objects.all())
48
        except BaseException, e:
49
            raise CommandError("Bootstrap failed.")
b/snf-astakos-app/astakos/im/management/commands/resource-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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import Resource, Service
38

  
39

  
40
class Command(BaseCommand):
41
    args = "<service> <resource> [<key>=<value>...]"
42
    help = "Add a resource"
43

  
44
    def handle(self, *args, **options):
45
        if len(args) < 2:
46
            raise CommandError("Invalid number of arguments")
47

  
48
        service_name = args[0]
49
        resource_name = args[1]
50

  
51
        try:
52
            service = Service.objects.get(name=service_name)
53
        except Service.DoesNotExist:
54
            raise CommandError("Invalid service name")
55
        else:
56
            try:
57
                resource = Resource(name=resource_name, service=service)
58
                resource.save()
59
            except IntegrityError, e:
60
                raise CommandError(e)
61
            # else:
62
#                 resource.meta.add(args[2:])
b/snf-astakos-app/astakos/im/management/commands/resource-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 Resource
39

  
40

  
41
class Command(BaseCommand):
42
    help = "List resources"
43

  
44
    option_list = BaseCommand.option_list + (
45
        make_option('-c',
46
                    action='store_true',
47
                    dest='csv',
48
                    default=False,
49
                    help="Use pipes to separate values"),
50
    )
51

  
52
    def handle(self, *args, **options):
53
        resources = Resource.objects.select_related().all()
54

  
55
        labels = ('id', 'service', 'name')
56
        columns = (3, 40, 40)
57

  
58
        if not options['csv']:
59
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
60
            self.stdout.write(line + '\n')
61
            sep = '-' * len(line)
62
            self.stdout.write(sep + '\n')
63

  
64
        for r in resources:
65
            fields = (str(r.id), r.service.name, r.name)
66

  
67
            if options['csv']:
68
                line = '|'.join(fields)
69
            else:
70
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
71

  
72
            self.stdout.write(line.encode('utf8') + '\n')
b/snf-astakos-app/astakos/im/management/commands/resource-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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import Resource
38

  
39

  
40
class Command(BaseCommand):
41
    args = "<resource>"
42
    help = "Add a resource"
43

  
44
    def handle(self, *args, **options):
45
        if len(args) < 1:
46
            raise CommandError("Invalid number of arguments")
47

  
48
        kwargs = {}
49
        if args[0].isdigit():
50
            kwargs['id'] = args[0]
51
        else:
52
            kwargs['name'] = args[0]
53

  
54
        try:
55
            r = Resource.objects.get(**kwargs)
56
        except Resource.DoesNotExist, e:
57
            raise CommandError("Invalid resource")
58
        r.delete()
/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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import Resource, Service
38

  
39

  
40
class Command(BaseCommand):
41
    args = "<service> <resource> [<key>=<value>...]"
42
    help = "Add a resource"
43

  
44
    def handle(self, *args, **options):
45
        if len(args) < 2:
46
            raise CommandError("Invalid number of arguments")
47

  
48
        service_name = args[0]
49
        resource_name = args[1]
50

  
51
        try:
52
            service = Service.objects.get(name=service_name)
53
        except Service.DoesNotExist:
54
            raise CommandError("Invalid service name")
55
        else:
56
            try:
57
                resource = Resource(name=resource_name, service=service)
58
                resource.save()
59
            except IntegrityError, e:
60
                raise CommandError(e)
61
            # else:
62
#                 resource.meta.add(args[2:])
/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 Resource
39

  
40

  
41
class Command(BaseCommand):
42
    help = "List resources"
43

  
44
    option_list = BaseCommand.option_list + (
45
        make_option('-c',
46
                    action='store_true',
47
                    dest='csv',
48
                    default=False,
49
                    help="Use pipes to separate values"),
50
    )
51

  
52
    def handle(self, *args, **options):
53
        resources = Resource.objects.select_related().all()
54

  
55
        labels = ('id', 'service', 'name')
56
        columns = (3, 40, 40)
57

  
58
        if not options['csv']:
59
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
60
            self.stdout.write(line + '\n')
61
            sep = '-' * len(line)
62
            self.stdout.write(sep + '\n')
63

  
64
        for r in resources:
65
            fields = (str(r.id), r.service.name, r.name)
66

  
67
            if options['csv']:
68
                line = '|'.join(fields)
69
            else:
70
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
71

  
72
            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
from django.db.utils import IntegrityError
36

  
37
from astakos.im.models import Resource
38

  
39

  
40
class Command(BaseCommand):
41
    args = "<resource>"
42
    help = "Add a resource"
43

  
44
    def handle(self, *args, **options):
45
        if len(args) < 1:
46
            raise CommandError("Invalid number of arguments")
47

  
48
        kwargs = {}
49
        if args[0].isdigit():
50
            kwargs['id'] = args[0]
51
        else:
52
            kwargs['name'] = args[0]
53

  
54
        try:
55
            r = Resource.objects.get(**kwargs)
56
        except Resource.DoesNotExist, e:
57
            raise CommandError("Invalid resource")
58
        r.delete()
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

  
39
class Command(BaseCommand):
40
    args = "<name> <url> [<icon>]"
41
    help = "Register a service"
42

  
43
    def handle(self, *args, **options):
44
        if len(args) < 2:
45
            raise CommandError("Invalid number of arguments")
46

  
47
        service = Service(name=args[0], url=args[1])
48
        if len(args) == 3:
49
            service.icon = args[2]
50
        try:
51
            service.save()
52
            self.stdout.write(
53
                'Service created with token: %s\n' % service.auth_token)
54
        except Exception, e:
55
            raise CommandError(e)
b/snf-astakos-app/astakos/im/management/commands/service-list.py
1
# Copyright 2012 GRNET S.A. All rights reserved.
2
#
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff