Commit 276f8a76 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

Use SynnefoCommand for django-admin commands

Instead of django's BaseCommand class, use out SynnefoCommand which
takes care of logging the command and its output.

Ref #3: Log all stdout/stderr for snf-manage invocations
parent 66c23906
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -35,11 +35,12 @@ import string
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import AuthProviderPolicyProfile as Profile
from snf_django.management.commands import SynnefoCommand
option_list = list(BaseCommand.option_list) + [
option_list = list(SynnefoCommand.option_list) + [
make_option('--update',
action='store_true',
dest='update',
......@@ -68,7 +69,7 @@ for p in POLICIES:
help="%s policy" % p.title()))
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<name> <provider_name>"
help = "Create a new authentication provider policy profile"
option_list = option_list
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,16 +31,17 @@
# interpreted as representing official policies, either expressed
# 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 snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<profile_name>"
help = "Remove an authentication provider policy"
option_list = BaseCommand.option_list + ()
option_list = SynnefoCommand.option_list + ()
def handle(self, *args, **options):
if len(args) != 1:
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -34,12 +34,13 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from snf_django.management.commands import SynnefoCommand
from astakos.im.models import AuthProviderPolicyProfile as Profile
from astakos.im.models import AstakosUser, Group
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--group',
action='append',
dest='groups',
......@@ -63,7 +64,7 @@ def update_profile(profile, users, groups):
profile.users.add(*users)
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<name> <provider_name>"
help = "Assign an existing authentication provider policy profile to " + \
"a user or group. All previously set "
......
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -32,15 +32,15 @@
# or implied, of GRNET S.A.
from django.core.management.base import NoArgsCommand
from django.core.management import call_command
from django.utils.importlib import import_module
from django.conf import settings
from astakos.im.models import SessionCatalog
from snf_django.management.commands import SynnefoCommand
class Command(NoArgsCommand):
class Command(SynnefoCommand):
help = "Cleanup sessions and session catalog"
def handle_noargs(self, **options):
......
# Copyright 2013 GRNET S.A. All rights reserved.
# Copyright 2013-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -32,15 +32,17 @@
# or implied, of GRNET S.A.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import Component
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<name>"
help = "Register a component"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--ui-url',
dest='ui_url',
default=None,
......
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -33,16 +33,17 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import Component
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<component ID or name>"
help = "Modify component attributes"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--ui-url',
dest='ui_url',
default=None,
......
# Copyright 2013 GRNET S.A. All rights reserved.
# Copyright 2013-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,12 +31,14 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.db import transaction
from astakos.im.models import Component
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<component ID or name>"
help = "Remove a component along with its registered services"
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,16 +31,14 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from optparse import make_option
from datetime import datetime
from django.db import transaction
from django.core.management.base import NoArgsCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.auth import fix_superusers
from snf_django.management.commands import SynnefoCommand
class Command(NoArgsCommand):
class Command(SynnefoCommand):
help = "Transform superusers created by syncdb into AstakosUser instances"
@transaction.commit_on_success
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,16 +31,17 @@
# interpreted as representing official policies, either expressed
# 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 Group
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<group name>"
help = "Create a group with the given name"
option_list = BaseCommand.option_list + ()
option_list = SynnefoCommand.option_list + ()
def handle(self, *args, **options):
if len(args) != 1:
......
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -34,16 +34,18 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.functions import (terminate, suspend, unsuspend,
reinstate, check_expiration,
approve_application, deny_application)
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
help = "Manage projects and applications"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--approve',
dest='approve',
metavar='<application id>',
......
......@@ -34,7 +34,7 @@
from optparse import make_option
from django.db.models import Q
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.db import transaction
from synnefo.util import units
from astakos.im import functions
......@@ -43,6 +43,7 @@ import astakos.api.projects as api
import synnefo.util.date as date_util
from snf_django.management import utils
from astakos.im.management.commands import _common
from snf_django.management.commands import SynnefoCommand
def make_policies(limits):
......@@ -112,10 +113,10 @@ def make_options():
return tuple(options)
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<project id> (or --all-base-projects)"
help = "Modify an already initialized project"
option_list = BaseCommand.option_list + make_options() + (
option_list = SynnefoCommand.option_list + make_options() + (
make_option('--all-base-projects',
action='store_true',
default=False,
......
......@@ -34,7 +34,7 @@
from optparse import make_option
from datetime import datetime
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.db import transaction
from snf_django.utils import reconcile
......@@ -44,9 +44,10 @@ from astakos.im import quotas
from astakos.im.functions import count_pending_app
import astakos.quotaholder_app.callpoint as qh
import astakos.quotaholder_app.exception as qh_exception
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
help = """Reconcile resource usage of Quotaholder with Astakos DB.
Detect unsynchronized usage between Quotaholder and Astakos DB resources
......@@ -54,7 +55,7 @@ class Command(BaseCommand):
"""
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option("--userid", dest="userid",
default=None,
help="Reconcile resources only for this user"),
......@@ -78,7 +79,7 @@ class Command(BaseCommand):
userid = options['userid']
project = options['project']
RESOURCES = [quotas.PENDING_APP_RESOURCE]
resources = [quotas.PENDING_APP_RESOURCE]
try:
astakos = Component.objects.get(name="astakos")
......@@ -109,11 +110,11 @@ class Command(BaseCommand):
db_project_holdings.update(user_holdings)
unsynced_users, users_pending, users_unknown =\
reconcile.check_users(self.stderr, RESOURCES,
reconcile.check_users(self.stderr, resources,
db_holdings, qh_holdings)
unsynced_projects, projects_pending, projects_unknown =\
reconcile.check_projects(self.stderr, RESOURCES,
reconcile.check_projects(self.stderr, resources,
db_project_holdings, qh_project_holdings)
pending_exists = users_pending or projects_pending
unknown_exists = users_unknown or projects_unknown
......
......@@ -32,19 +32,20 @@
# or implied, of GRNET S.A.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from snf_django.management import utils
from astakos.im.models import Resource
from astakos.im import register
from ._common import style_options, check_style, units
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<resource name>"
help = "Modify a resource's quota defaults and boolean flags."
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--base-default',
metavar='<limit>',
help="Specify default quota for base projects"),
......
# Copyright 2012-2013 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -32,13 +32,14 @@
# or implied, of GRNET S.A.
from django.utils import simplejson as json
from django.core.management.base import NoArgsCommand
# import from settings, after any post-processing
from astakos.im.settings import astakos_services
from synnefo.lib.services import filter_public
from snf_django.management.commands import SynnefoCommand
class Command(NoArgsCommand):
class Command(SynnefoCommand):
help = "Export Astakos services in JSON format."
def handle(self, *args, **options):
......
# Copyright 2013 GRNET S.A. All rights reserved.
# Copyright 2013-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -34,18 +34,19 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.utils import simplejson as json
from astakos.im.register import add_service, add_resource, RegisterException
from snf_django.management.commands import SynnefoCommand
from astakos.im.models import Component
from ._common import read_from_file
class Command(BaseCommand):
class Command(SynnefoCommand):
help = "Register services"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--json',
dest='json',
metavar='<json.file>',
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -33,13 +33,14 @@
from os.path import abspath
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.db import transaction
from astakos.im.models import ApprovalTerms, AstakosUser
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<location>"
help = "Insert approval terms"
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,15 +31,16 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im import activation_backends
activation_backend = activation_backends.get_backend()
from ._common import get_user
from snf_django.management.commands import SynnefoCommand
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<user ID or email> [user ID or email] ..."
help = "Sends an activation email to one or more users"
......
......@@ -32,22 +32,22 @@
# or implied, of GRNET S.A.
from optparse import make_option
from datetime import datetime
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from astakos.im.models import AstakosUser, get_latest_terms
from snf_django.management.commands import SynnefoCommand
from astakos.im.auth import make_local_user
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<email> <first name> <last name>"
help = "Create a user"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--password',
dest='password',
metavar='PASSWORD',
......
# Copyright 2012, 2013, 2014 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -38,23 +38,24 @@ from optparse import make_option
from django.core import management
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from astakos.im.models import AstakosUser
from astakos.im import activation_backends
from snf_django.management.commands import SynnefoCommand
from ._common import (remove_user_permission, add_user_permission, is_uuid)
activation_backend = activation_backends.get_backend()
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<user ID> (or --all)"
help = "Modify a user's attributes"
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--all',
action='store_true',
default=False,
......
# Copyright 2013 GRNET S.A. All rights reserved.
# Copyright 2013-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,12 +31,14 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.db import transaction
from snf_django.management.commands import SynnefoCommand
from astakos.oa2.models import Client
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<client ID or identifier>"
help = "Remove an oauth2 client along with its registered redirect urls"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment