From 6ce4d6b8777e0ac8c35af58054c72174775d601f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 30 Jan 2021 14:59:49 +0100 Subject: [PATCH] fixed make_options for all commands --- .../commands/postupgradeorchestra.py | 49 ++++--- orchestra/management/commands/setupcelery.py | 41 +++--- orchestra/management/commands/setupnginx.py | 1 - orchestra/management/commands/setuppostfix.py | 123 ++++++++++++------ .../management/commands/setuppostgres.py | 1 - .../management/commands/startservices.py | 15 ++- .../management/commands/upgradeorchestra.py | 31 +++-- 7 files changed, 172 insertions(+), 89 deletions(-) diff --git a/orchestra/management/commands/postupgradeorchestra.py b/orchestra/management/commands/postupgradeorchestra.py index 0e453558..992b5f90 100644 --- a/orchestra/management/commands/postupgradeorchestra.py +++ b/orchestra/management/commands/postupgradeorchestra.py @@ -1,6 +1,5 @@ import re import os -from optparse import make_option from django.core.management.base import BaseCommand @@ -19,26 +18,44 @@ def deprecate_periodic_tasks(names): class Command(BaseCommand): - def __init__(self, *args, **kwargs): - super(Command, self).__init__(*args, **kwargs) - self.option_list = BaseCommand.option_list + ( - make_option('--no-restart', action='store_false', dest='restart', default=True, - help='Only install local requirements'), - make_option('--specifics', action='store_true', dest='specifics_only', - default=False, help='Only run version specific operations'), - make_option('--no-upgrade-notes', action='store_false', default=True, - dest='print_upgrade_notes', help='Do not print specific upgrade notes'), - make_option('--from', dest='version', default=False, - help="Orchestra's version from where you are upgrading, i.e 0.0.1"), - ) - - option_list = BaseCommand.option_list help = 'Upgrades django-orchestra installation' # This command must be able to run in an environment with unsatisfied dependencies leave_locale_alone = True can_import_settings = False requires_model_validation = False - + + def __init__(self, *args, **kwargs): + super(Command, self).__init__(*args, **kwargs) + + def add_arguments(self, parser): + parser.add_argument( + '--no-restart', + action='store_false', + dest='restart', + default=True, + help='Only install local requirements' + ) + parser.add_argument( + '--specifics', + action='store_true', + dest='specifics_only', + default=False, + help='Only run version specific operations' + ) + parser.add_argument( + '--no-upgrade-notes', + action='store_false', + default=True, + dest='print_upgrade_notes', + help='Do not print specific upgrade notes' + ) + parser.add_argument( + '--from', + dest='version', + default=False, + help="Orchestra's version from where you are upgrading, i.e 0.0.1" + ) + @check_root def handle(self, *args, **options): version = options.get('version') diff --git a/orchestra/management/commands/setupcelery.py b/orchestra/management/commands/setupcelery.py index c343d6e8..b2cc387a 100644 --- a/orchestra/management/commands/setupcelery.py +++ b/orchestra/management/commands/setupcelery.py @@ -1,5 +1,4 @@ import textwrap -from optparse import make_option from os import path from django.core.management.base import BaseCommand @@ -10,22 +9,34 @@ from orchestra.utils.sys import run, check_root class Command(BaseCommand): - def __init__(self, *args, **kwargs): - super(Command, self).__init__(*args, **kwargs) - self.option_list = BaseCommand.option_list + ( - make_option('--username', dest='username', default='orchestra', - help='Specifies the system user that would run celeryd.'), - make_option('--processes', dest='processes', default=2, - help='Number of celeryd processes.'), - make_option('--noinput', action='store_false', dest='interactive', default=True, - help='Tells Django to NOT prompt the user for input of any kind. ' - 'You must use --username with --noinput, and must contain the ' - 'cleleryd process owner, which is the user how will perform tincd updates'), - ) - - option_list = BaseCommand.option_list help = 'Configure Celeryd to run with your orchestra instance.' + def __init__(self, *args, **kwargs): + super(Command, self).__init__(*args, **kwargs) + + def add_arguments(self, parser): + parser.add_argument( + '--username', + dest='username', + default='orchestra', + help='Specifies the system user that would run celeryd.' + ) + parser.add_argument( + '--processes', + dest='processes', + default=2, + help='Number of celeryd processes.' + ) + parser.add_argument( + '--noinput', + action='store_false', + dest='interactive', + default=True, + help='''Tells Django to NOT prompt the user for input of any kind. + You must use --username with --noinput, and must contain the + cleleryd process owner, which is the user how will perform tincd updates''' + ) + @check_root def handle(self, *args, **options): context = { diff --git a/orchestra/management/commands/setupnginx.py b/orchestra/management/commands/setupnginx.py index 98ca84f7..db15b9ee 100644 --- a/orchestra/management/commands/setupnginx.py +++ b/orchestra/management/commands/setupnginx.py @@ -1,6 +1,5 @@ import os import textwrap -from optparse import make_option from os.path import expanduser from django.conf import settings diff --git a/orchestra/management/commands/setuppostfix.py b/orchestra/management/commands/setuppostfix.py index a3a75239..0365015f 100644 --- a/orchestra/management/commands/setuppostfix.py +++ b/orchestra/management/commands/setuppostfix.py @@ -1,52 +1,97 @@ import os -from optparse import make_option - from django.core.management.base import BaseCommand from orchestra.utils.sys import run, check_root class Command(BaseCommand): + help = 'Setup Postfix.' + def __init__(self, *args, **kwargs): super(Command, self).__init__(*args, **kwargs) - self.option_list = BaseCommand.option_list + ( - make_option('--db_name', dest='db_name', default='orchestra', - help='Specifies the database to create.'), - make_option('--db_user', dest='db_user', default='orchestra', - help='Specifies the database to create.'), - make_option('--db_password', dest='db_password', default='orchestra', - help='Specifies the database to create.'), - make_option('--db_host', dest='db_host', default='localhost', - help='Specifies the database to create.'), - make_option('--vmail_username', dest='vmail_username', default='vmail', - help='Specifies username in the operating system (default=vmail).'), - make_option('--vmail_uid', dest='vmail_uid', default='5000', - help='UID of user (default=5000).'), - make_option('--vmail_groupname', dest='vmail_groupname', default='vmail', - help='Specifies the groupname in the operating system (default=vmail).'), - make_option('--vmail_gid', dest='vmail_gid', default='5000', - help='GID of user (default=5000).'), - make_option('--vmail_home', dest='vmail_home', default='/var/vmail', - help='$HOME of user (default=/var/vmail).'), - - make_option('--dovecot_dir', dest='dovecot_dir', default='/etc/dovecot', - help='Dovecot root directory (default=/etc/dovecot).'), - - make_option('--postfix_dir', dest='postfix_dir', default='/etc/postfix', - help='Postfix root directory (default=/etc/postfix).'), - - make_option('--amavis_dir', dest='amavis_dir', default='/etc/amavis', - help='Amavis root directory (default=/etc/amavis).'), - - make_option('--noinput', action='store_false', dest='interactive', default=True, - help='Tells Django to NOT prompt the user for input of any kind. ' - 'You must use --username with --noinput, and must contain the ' - 'cleeryd process owner, which is the user how will perform tincd updates'), - ) - - option_list = BaseCommand.option_list - help = 'Setup Postfix.' + def add_arguments(self, parser): + parser.add_argument( + '--db_name', + dest='db_name', + default='orchestra', + help='Specifies the database to create.' + ) + parser.add_argument( + '--db_user', + dest='db_user', + default='orchestra', + help='Specifies the database to create.' + ) + parser.add_argument( + '--db_password', + dest='db_password', + default='orchestra', + help='Specifies the database to create.' + ) + parser.add_argument( + '--db_host', + dest='db_host', + default='localhost', + help='Specifies the database to create.' + ) + parser.add_argument( + '--vmail_username', + dest='vmail_username', + default='vmail', + help='Specifies username in the operating system (default=vmail).' + ) + parser.add_argument( + '--vmail_uid', + dest='vmail_uid', + default='5000', + help='UID of user (default=5000).' + ) + parser.add_argument( + '--vmail_groupname', + dest='vmail_groupname', + default='vmail', + help='Specifies the groupname in the operating system (default=vmail).' + ) + parser.add_argument( + '--vmail_gid', + dest='vmail_gid', + default='5000', + help='GID of user (default=5000).' + ) + parser.add_argument( + '--vmail_home', + dest='vmail_home', + default='/var/vmail', + help='$HOME of user (default=/var/vmail).' + ) + parser.add_argument( + '--dovecot_dir', + dest='dovecot_dir', + default='/etc/dovecot', + help='Dovecot root directory (default=/etc/dovecot).' + ) + parser.add_argument( + '--postfix_dir', + dest='postfix_dir', + default='/etc/postfix', + help='Postfix root directory (default=/etc/postfix).' + ) + parser.add_argument( + '--amavis_dir', + dest='amavis_dir', + default='/etc/amavis', + help='Amavis root directory (default=/etc/amavis).' + ) + parser.add_argument( + '--noinput', + action='store_false', + dest='interactive', + default=True, + help='''Tells Django to NOT prompt the user for input of any kind. + You must use --username with --noinput, and must contain the + cleeryd process owner, which is the user how will perform tincd updates''' + ) @check_root def handle(self, *args, **options): diff --git a/orchestra/management/commands/setuppostgres.py b/orchestra/management/commands/setuppostgres.py index 493b42bd..a39ec377 100644 --- a/orchestra/management/commands/setuppostgres.py +++ b/orchestra/management/commands/setuppostgres.py @@ -1,6 +1,5 @@ import os import textwrap -from optparse import make_option from django.conf import settings from django.core.management.base import BaseCommand, CommandError diff --git a/orchestra/management/commands/startservices.py b/orchestra/management/commands/startservices.py index 6bfe9f17..55953e6a 100644 --- a/orchestra/management/commands/startservices.py +++ b/orchestra/management/commands/startservices.py @@ -1,5 +1,3 @@ -from optparse import make_option - from django.core.management.base import BaseCommand from orchestra import settings @@ -30,9 +28,16 @@ def flatten(nested, depth=0): class ManageServiceCommand(BaseCommand): def __init__(self, *args, **kwargs): super(ManageServiceCommand, self).__init__(*args, **kwargs) - self.option_list = BaseCommand.option_list + tuple( - make_option('--no-%s' % service, action='store_false', dest=service, default=True, - help='Do not %s %s' % (self.action, service)) for service in flatten(self.services) + + + def add_arguments(self, parser): + for service in flatten(self.services): + parser.add_argument( + '--no-%s' % service, + action='store_false', + dest=service, + default=True, + help='Do not %s %s' % (self.action, service) ) @check_root diff --git a/orchestra/management/commands/upgradeorchestra.py b/orchestra/management/commands/upgradeorchestra.py index 3b7fd846..ccbdab91 100644 --- a/orchestra/management/commands/upgradeorchestra.py +++ b/orchestra/management/commands/upgradeorchestra.py @@ -3,7 +3,6 @@ import os import random import string from distutils.sysconfig import get_python_lib -from optparse import make_option from django.core.management import call_command from django.core.management.base import BaseCommand, CommandError @@ -26,20 +25,28 @@ def get_existing_pip_installation(): class Command(BaseCommand): - def __init__(self, *args, **kwargs): - super(Command, self).__init__(*args, **kwargs) - self.option_list = BaseCommand.option_list + ( - make_option('--pip_only', action='store_true', dest='pip_only', default=False, - help='Only run "pip install django-orchestra --upgrade"'), - make_option('--orchestra_version', dest='version', default=False, - help='Specifies what version of the Orchestra you want to install'), - ) - - option_list = BaseCommand.option_list help = "Upgrading Orchestra's installation. Desired version is accepted as argument" can_import_settings = False leave_locale_alone = True - + + def __init__(self, *args, **kwargs): + super(Command, self).__init__(*args, **kwargs) + + def add_arguments(self, parser): + parser.add_argument( + '--pip_only', + action='store_true', + dest='pip_only', + default=False, + help='Only run "pip install django-orchestra --upgrade"' + ) + parser.add_argument( + '--orchestra_version', + dest='version', + default=False, + help='Specifies what version of the Orchestra you want to install' + ) + @check_root def handle(self, *args, **options): current_version = get_version()