Replace django-subcommand2 by custom code

This commit is contained in:
Jérôme Lebleu
2020-01-13 14:24:25 +01:00
parent 817015688d
commit 2241b1a3a2
2 changed files with 27 additions and 4 deletions
+27 -3
View File
@@ -1,6 +1,6 @@
"""Modoboa main management command."""
from subcommand.base import SubcommandCommand
from django.core.management.base import BaseCommand
from .subcommands._export import ExportCommand
from .subcommands._import import ImportCommand
@@ -9,13 +9,13 @@ from .subcommands._mx import CheckMXRecords
from .subcommands._repair import Repair
class Command(SubcommandCommand):
class Command(BaseCommand):
"""Top management command for modoboa.
$ python manage.py modo
"""
help = "Modoboa top management command." # NOQA:A003
help = "Modoboa top management command."
subcommands = {
"export": ExportCommand,
@@ -24,3 +24,27 @@ class Command(SubcommandCommand):
"manage_dkim_keys": ManageDKIMKeys,
"repair": Repair,
}
def add_arguments(self, parser):
subparsers = parser.add_subparsers(
dest='subcommand', title='subcommands'
)
# required argument is added in Python 3.7
subparsers.required = True
for command_name, command_class in self.subcommands.items():
command = command_class(self.stdout, self.stderr)
command.style = self.style
subparser = subparsers.add_parser(
command_name, help=command_class.help
)
# This is needed to output console friendly errors
subparser.called_from_command_line = self._called_from_command_line
command.add_arguments(subparser)
subparser.set_defaults(command=command)
def execute(self, *args, **options):
return options.pop('command').execute(*args, **options)
-1
View File
@@ -2,7 +2,6 @@ django>=2.0,<2.1
django-braces==1.14.0
django-ckeditor==5.8.0
django-reversion==3.0.5
django-subcommand2==0.1.1
django-xforwardedfor-middleware==2.0
dj-database-url