Browse Source

Change commands to use add_arguments

TheKit 8 years ago
parent
commit
be9c20b0d4

+ 1 - 1
misago/core/management/commands/misagodbrelations.py

@@ -35,7 +35,7 @@ class Command(BaseCommand):
                             self.stdout.write(field_pattern % (
                                 field.name,
                                 field.__class__.__name__,
-                                field.related.model.__name__,
+                                field.related_model.__name__,
                                 field.rel.on_delete.__name__,
                             ))
 

+ 10 - 1
misago/core/management/commands/remakemisagochecksums.py

@@ -8,12 +8,21 @@ from ...signals import secret_key_changed
 class Command(BaseCommand):
     help = 'Regenerates Misago checksums after SECRET_KEY changed.'
 
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '--force',
+            action='store_true',
+            dest='force',
+            default=False,
+            help='Do not ask for confirmation',
+        )
+
     def handle(self, *args, **options):
         message = force_str("This will replace all checksums "
                             "in database with new ones, marking "
                             "all data as trusted. Are you sure "
                             "you wish to continue? [Y/n]")
-        if '--force' in args or input(message).strip().lower() == "y":
+        if options['force'] or input(message).strip().lower() == "y":
             self.stdout.write("\nRegenerating checksums...")
             secret_key_changed.send(self)
             self.stdout.write("\nDone!")

+ 4 - 6
misago/core/management/commands/testemailsetup.py

@@ -8,16 +8,14 @@ from django.core.validators import validate_email
 class Command(BaseCommand):
     help = 'Sends test e-mail to given address'
 
+    def add_arguments(self, parser):
+        parser.add_argument('email', type=str)
+
     def handle(self, *args, **options):
         try:
-            if len(args) != 1:
-                raise ValueError()
-            email = args[0]
+            email = options['email']
             validate_email(email)
             self.send_message(email)
-        except ValueError:
-            self.stderr.write("Command accepts exactly "
-                              "one argument (e-mail address)")
         except ValidationError:
             self.stderr.write("This isn't valid e-mail address")
 

+ 19 - 24
misago/users/management/commands/createsuperuser.py

@@ -4,7 +4,6 @@ works with double authentication fields on user model
 """
 import sys
 from getpass import getpass
-from optparse import make_option
 
 from django.contrib.auth import get_user_model
 from django.core.exceptions import ValidationError
@@ -23,29 +22,25 @@ class NotRunningInTTYException(Exception):
 class Command(BaseCommand):
     help = 'Used to create a superuser.'
 
-    def __init__(self, *args, **kwargs):
-        super(Command, self).__init__(*args, **kwargs)
-
-        self.option_list = BaseCommand.option_list + (
-            make_option('--username', dest='username', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--email', dest='email', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--password', dest='password', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--noinput', action='store_false', dest='interactive',
-                        default=True,
-                        help=('Tells Miago to NOT prompt the user for input '
-                              'of any kind. You must use --username with '
-                              '--noinput, along with an option for any other '
-                              'required field. Superusers created with '
-                              '--noinput will  not be able to log in until '
-                              'they\'re given a valid password.')),
-            make_option('--database', action='store', dest='database',
-                        default=DEFAULT_DB_ALIAS,
-                        help=('Specifies the database to use. '
-                              'Default is "default".')),
-        )
+    def add_arguments(self, parser):
+        parser.add_argument('--username', dest='username', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--email', dest='email', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--password', dest='password', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--noinput', action='store_false', dest='interactive',
+                    default=True,
+                    help=('Tells Misago to NOT prompt the user for input '
+                          'of any kind. You must use --username with '
+                          '--noinput, along with an option for any other '
+                          'required field. Superusers created with '
+                          '--noinput will  not be able to log in until '
+                          'they\'re given a valid password.'))
+        parser.add_argument('--database', action='store', dest='database',
+                    default=DEFAULT_DB_ALIAS,
+                    help=('Specifies the database to use. '
+                          'Default is "default".'))
 
     def execute(self, *args, **options):
         self.stdin = options.get('stdin', sys.stdin)  # Used for testing