Revision 7eabbd72 snf-astakos-app/astakos/im/management/commands/project-list.py
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