Skip to content
Snippets Groups Projects
Commit 03e5ef16 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Change astakos show commands

* rename `invitation-details` command to 
`invitation-show` to conform with the rest 
synnefo show commands
* Enable the --output-format option (by changing 
them to inherit by `synnefo.webproject.management.commands.SynnefoCommand`
instead
* print the output using
`synnefo.webproject.management.utils.pprint_table` 
parent fe7e2b18
No related branches found
No related tags found
No related merge requests found
...@@ -31,15 +31,16 @@ ...@@ -31,15 +31,16 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import CommandError
from astakos.im.models import Invitation from astakos.im.models import Invitation
from synnefo.webproject.management.commands import SynnefoCommand
from ._common import format from synnefo.webproject.management import utils
class Command(BaseCommand): class Command(SynnefoCommand):
args = "<invitation ID>" args = "<invitation ID or code>"
help = "Show invitation info" help = "Show invitation info"
def handle(self, *args, **options): def handle(self, *args, **options):
...@@ -49,7 +50,10 @@ class Command(BaseCommand): ...@@ -49,7 +50,10 @@ class Command(BaseCommand):
try: try:
invitation = Invitation.objects.get(id=int(args[0])) invitation = Invitation.objects.get(id=int(args[0]))
except Invitation.DoesNotExist: except Invitation.DoesNotExist:
raise CommandError("Unknown invitation id '%s'" % (args[0],)) try:
invitation = Invitation.objects.get(code=args[0])
except Invitation.DoesNotExist:
raise CommandError("Unknown invitation id '%s'" % (args[0],))
kv = { kv = {
'id': invitation.id, 'id': invitation.id,
...@@ -63,6 +67,5 @@ class Command(BaseCommand): ...@@ -63,6 +67,5 @@ class Command(BaseCommand):
'invitater email': invitation.inviter.email, 'invitater email': invitation.inviter.email,
} }
for key, val in sorted(kv.items()): utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
line = '%s: %s\n' % (key.rjust(18), format(val)) options["output_format"], vertical=True)
self.stdout.write(line)
...@@ -32,15 +32,15 @@ ...@@ -32,15 +32,15 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import CommandError
from synnefo.lib.ordereddict import OrderedDict from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from astakos.im.models import Chain, ProjectApplication from astakos.im.models import Chain, ProjectApplication
from ._common import format
class Command(SynnefoCommand):
class Command(BaseCommand):
args = "<id or name>" args = "<id or name>"
help = """ help = """
Show project details. Show project details.
...@@ -52,7 +52,7 @@ class Command(BaseCommand): ...@@ -52,7 +52,7 @@ class Command(BaseCommand):
contains the given string contains the given string
""" """
option_list = BaseCommand.option_list + ( option_list = SynnefoCommand.option_list + (
make_option('--app', make_option('--app',
action='store_true', action='store_true',
dest='app', dest='app',
...@@ -63,17 +63,17 @@ class Command(BaseCommand): ...@@ -63,17 +63,17 @@ class Command(BaseCommand):
action='store_true', action='store_true',
dest='pending', dest='pending',
default=False, default=False,
help=("For a given project, show also pending modifications " help=("For a given project, show also pending modifications"
"(applications), if any") "(applications), if any")
), ),
) )
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 1: if len(args) != 1:
raise CommandError("Please provide project ID or name") raise CommandError("Please provide project ID or name")
show_pending = bool(options['pending']) show_pending = bool(options['pending'])
search_apps = options['app'] search_apps = options['app']
name_or_id = args[0] name_or_id = args[0]
is_id = name_or_id.isdigit() is_id = name_or_id.isdigit()
...@@ -93,13 +93,8 @@ class Command(BaseCommand): ...@@ -93,13 +93,8 @@ class Command(BaseCommand):
raise CommandError(msg) raise CommandError(msg)
for info in infolist: for info in infolist:
self.show_info(info) utils.pprint_table(self.stdout, [info.values()], info.keys(),
options["output_format"], vertical=True)
def show_info(self, info):
for key, val in info.items():
line = '%s: %s\n' % (key.rjust(22), format(val))
self.stdout.write(line)
self.stdout.write('\n')
def app_info(name_or_id, is_id): def app_info(name_or_id, is_id):
...@@ -111,6 +106,7 @@ def app_info(name_or_id, is_id): ...@@ -111,6 +106,7 @@ def app_info(name_or_id, is_id):
except ProjectApplication.DoesNotExist: except ProjectApplication.DoesNotExist:
return [] return []
def get_chains(name_or_id, is_id): def get_chains(name_or_id, is_id):
if is_id: if is_id:
try: try:
...@@ -120,6 +116,7 @@ def get_chains(name_or_id, is_id): ...@@ -120,6 +116,7 @@ def get_chains(name_or_id, is_id):
else: else:
return Chain.objects.search_by_name(name_or_id) return Chain.objects.search_by_name(name_or_id)
def collect_info(chains, pending): def collect_info(chains, pending):
states = [chain.full_state() for chain in chains] states = [chain.full_state() for chain in chains]
...@@ -128,6 +125,7 @@ def collect_info(chains, pending): ...@@ -128,6 +125,7 @@ def collect_info(chains, pending):
infolist += (chain_fields(state, pending)) infolist += (chain_fields(state, pending))
return infolist return infolist
def chain_fields((s, project, app), request=False): def chain_fields((s, project, app), request=False):
l = [] l = []
if project: if project:
...@@ -138,28 +136,29 @@ def chain_fields((s, project, app), request=False): ...@@ -138,28 +136,29 @@ def chain_fields((s, project, app), request=False):
l = [app_fields(app)] l = [app_fields(app)]
return l return l
def app_fields(app): def app_fields(app):
mem_limit = app.limit_on_members_number mem_limit = app.limit_on_members_number
mem_limit_show = mem_limit if mem_limit is not None else "unlimited" mem_limit_show = mem_limit if mem_limit is not None else "unlimited"
d = OrderedDict([ d = OrderedDict([
('project id', app.chain), ('project id', app.chain),
('application id', app.id), ('application id', app.id),
('name', app.name), ('name', app.name),
('status', app.state_display()), ('status', app.state_display()),
('owner', app.owner), ('owner', app.owner),
('applicant', app.applicant), ('applicant', app.applicant),
('homepage', app.homepage), ('homepage', app.homepage),
('description', app.description), ('description', app.description),
('comments for review', app.comments), ('comments for review', app.comments),
('request issue date', app.issue_date), ('request issue date', app.issue_date),
('request start date', app.start_date), ('request start date', app.start_date),
('request end date', app.end_date), ('request end date', app.end_date),
('resources', app.resource_policies), ('resources', app.resource_policies),
('join policy', app.member_join_policy_display), ('join policy', app.member_join_policy_display),
('leave policy', app.member_leave_policy_display), ('leave policy', app.member_leave_policy_display),
('max members', mem_limit_show), ('max members', mem_limit_show),
]) ])
return d return d
...@@ -168,11 +167,11 @@ def project_fields(s, project, last_app): ...@@ -168,11 +167,11 @@ def project_fields(s, project, last_app):
app = project.application app = project.application
d = OrderedDict([ d = OrderedDict([
('project id', project.id), ('project id', project.id),
('application id', app.id), ('application id', app.id),
('name', app.name), ('name', app.name),
('status', Chain.state_display(s)), ('status', Chain.state_display(s)),
]) ])
if s in Chain.PENDING_STATES: if s in Chain.PENDING_STATES:
d.update([('pending application', last_app.id)]) d.update([('pending application', last_app.id)])
...@@ -200,10 +199,10 @@ def project_fields(s, project, last_app): ...@@ -200,10 +199,10 @@ def project_fields(s, project, last_app):
('leave policy', app.member_leave_policy_display), ('leave policy', app.member_leave_policy_display),
('max members', mem_limit_show), ('max members', mem_limit_show),
('total members', project.members_count()), ('total members', project.members_count()),
]) ])
memberships = project.projectmembership_set memberships = project.projectmembership_set
accepted = [str(m.person) for m in memberships.any_accepted()] accepted = [str(m.person) for m in memberships.any_accepted()]
requested = [str(m.person) for m in memberships.requested()] requested = [str(m.person) for m in memberships.requested()]
suspended = [str(m.person) for m in memberships.suspended()] suspended = [str(m.person) for m in memberships.suspended()]
......
...@@ -31,17 +31,15 @@ ...@@ -31,17 +31,15 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import CommandError
from astakos.im.models import AuthProviderPolicyProfile as Profile from astakos.im.models import AuthProviderPolicyProfile as Profile
from synnefo.lib.ordereddict import OrderedDict from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from ._common import format
import uuid class Command(SynnefoCommand):
class Command(BaseCommand):
args = "<profile_name>" args = "<profile_name>"
help = "Show authentication provider profile details" help = "Show authentication provider profile details"
...@@ -65,5 +63,5 @@ class Command(BaseCommand): ...@@ -65,5 +63,5 @@ class Command(BaseCommand):
('users', profile.users.all()) ('users', profile.users.all())
]) ])
self.stdout.write(format(kv)) utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
self.stdout.write('\n') options["output_format"], vertical=True)
...@@ -31,19 +31,20 @@ ...@@ -31,19 +31,20 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import CommandError
from astakos.im.models import AstakosUser, get_latest_terms from astakos.im.models import AstakosUser, get_latest_terms
from astakos.im.util import model_to_dict
from synnefo.lib.ordereddict import OrderedDict from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from ._common import format from ._common import format
import uuid import uuid
class Command(BaseCommand): class Command(SynnefoCommand):
args = "<user ID or email>" args = "<user ID or email or uuid>"
help = "Show user info" help = "Show user info"
def handle(self, *args, **options): def handle(self, *args, **options):
...@@ -115,5 +116,5 @@ class Command(BaseCommand): ...@@ -115,5 +116,5 @@ class Command(BaseCommand):
if has_signed_terms: if has_signed_terms:
kv['date_signed_terms'] = user.date_signed_terms kv['date_signed_terms'] = user.date_signed_terms
self.stdout.write(format(kv)) utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
self.stdout.write('\n') options["output_format"], vertical=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment