Revision 7eabbd72

b/snf-astakos-app/astakos/im/management/commands/_common.py
142 142
        return 1
143 143
    except Permission.DoesNotExist:
144 144
        return -1
145

  
146
def shortened(s, limit, suffix=True):
147
    length = len(s)
148
    if length <= limit:
149
        return s
150
    else:
151
        display = limit - 2
152
        if suffix:
153
            return '..' + s[-display:]
154
        else:
155
            return s[:display] + '..'
/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 ProjectApplication
39
from astakos.im.functions import approve_application
40
from astakos.im.project_xctx import project_transaction_context
41

  
42
class Command(BaseCommand):
43
    args = "<project application id>"
44
    help = "Approve project application"
45

  
46
    def handle(self, *args, **options):
47
        if len(args) < 1:
48
            raise CommandError("Please provide an application id")
49

  
50
        try:
51
            id = int(args[0])
52
        except ValueError:
53
            raise CommandError('Invalid id')
54
        else:
55
            approve(id)
56

  
57
@project_transaction_context(sync=True)
58
def approve(app, ctx=None):
59
    try:
60
        approve_application(app)
61
    except BaseException as e:
62
        if ctx:
63
            ctx.mark_rollback()
64
            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.core.exceptions import PermissionDenied
38
from django.db import transaction
39

  
40
from astakos.im.models import ProjectApplication
41
from astakos.im.functions import deny_application
42

  
43
class Command(BaseCommand):
44
    args = "<project application id>"
45
    help = "Deny a project application"
46

  
47
    @transaction.commit_on_success
48
    def handle(self, *args, **options):
49
        if len(args) < 1:
50
            raise CommandError("Please provide an application identifier")
51
        try:
52
            app_id = int(args[0])
53
        except ValueError:
54
            raise CommandError('Invalid id')
55
        else:
56
            try:
57
                deny_application(app_id)
58
            except (PermissionDenied, IOError):
59
                raise CommandError('Invalid id')
b/snf-astakos-app/astakos/im/management/commands/project-application-approve.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 ProjectApplication
39
from astakos.im.functions import approve_application
40
from astakos.im.project_xctx import project_transaction_context
41

  
42
class Command(BaseCommand):
43
    args = "<project application id>"
44
    help = "Approve project application"
45

  
46
    def handle(self, *args, **options):
47
        if len(args) < 1:
48
            raise CommandError("Please provide an application id")
49

  
50
        try:
51
            id = int(args[0])
52
        except ValueError:
53
            raise CommandError('Invalid id')
54
        else:
55
            approve(id)
56

  
57
@project_transaction_context(sync=True)
58
def approve(app, ctx=None):
59
    try:
60
        approve_application(app)
61
    except BaseException as e:
62
        if ctx:
63
            ctx.mark_rollback()
64
            raise CommandError(e)
b/snf-astakos-app/astakos/im/management/commands/project-application-deny.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.core.exceptions import PermissionDenied
38
from django.db import transaction
39

  
40
from astakos.im.models import ProjectApplication
41
from astakos.im.functions import deny_application
42

  
43
class Command(BaseCommand):
44
    args = "<project application id>"
45
    help = "Deny a project application"
46

  
47
    @transaction.commit_on_success
48
    def handle(self, *args, **options):
49
        if len(args) < 1:
50
            raise CommandError("Please provide an application identifier")
51
        try:
52
            app_id = int(args[0])
53
        except ValueError:
54
            raise CommandError('Invalid id')
55
        else:
56
            try:
57
                deny_application(app_id)
58
            except (PermissionDenied, IOError):
59
                raise CommandError('Invalid id')
b/snf-astakos-app/astakos/im/management/commands/project-list.py
36 36
from django.core.management.base import NoArgsCommand
37 37

  
38 38
from astakos.im.models import Chain
39
from ._common import format_bool
39
from ._common import format_bool, shortened
40

  
40 41

  
41 42
class Command(NoArgsCommand):
42 43
    help = "List projects"
......
55 56
    )
56 57

  
57 58
    def handle_noargs(self, **options):
58
        labels = ('ProjectID', 'Name', 'Owner', 'Status')
59
        columns = (9, 24, 24, 23)
59
        labels = ('ProjID', 'Name', 'Owner', 'Status', 'AppID')
60
        columns = (7, 23, 23, 20, 7)
60 61

  
61 62
        if not options['csv']:
62 63
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
......
70 71

  
71 72
        for info in chain_info(chain_dict):
72 73

  
73
            fields = (
74
                info['projectid'],
75
                info['name'],
76
                info['owner'],
77
                info['status'],
78
            )
74
            fields = [
75
                (info['projectid'], False),
76
                (info['name'], True),
77
                (info['owner'], True),
78
                (info['status'], False),
79
                (info['appid'], False),
80
            ]
79 81

  
80 82
            if options['csv']:
81 83
                line = '|'.join(fields)
82 84
            else:
83
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
85
                output = []
86
                for (field, shorten), width in zip(fields, columns):
87
                    s = shortened(field, width) if shorten else field
88
                    s = s.rjust(width)
89
                    output.append(s)
90

  
91
                line = ' '.join(output)
84 92

  
85 93
            self.stdout.write(line + '\n')
86 94

  
......
96 104
    for chain, (state, project, app) in chain_dict.iteritems():
97 105
        status = Chain.state_display(state)
98 106
        if state in Chain.PENDING_STATES:
99
            status += " %s" % (app.id,)
107
            appid = str(app.id)
108
        else:
109
            appid = ""
100 110

  
101 111
        d = {
102 112
            'projectid' : str(chain),
103
            'name'  : str(project.name if project else app.name),
113
            'name'  : str(project.application.name if project else app.name),
104 114
            'owner' : app.owner.realname,
105 115
            'status': status,
116
            'appid' : appid,
106 117
            }
107 118
        l.append(d)
108 119
    return l

Also available in: Unified diff