From 2b5f0e9f05a47746ca89830fd44346d6263a5c81 Mon Sep 17 00:00:00 2001 From: Fabian Weisshaar Date: Thu, 28 Dec 2017 17:46:46 +0100 Subject: [PATCH] update BaseCommand option_list for Django 1.11 --- nsupdate/management/commands/domains.py | 30 ++++++-------- nsupdate/management/commands/faults.py | 50 +++++++++--------------- nsupdate/management/commands/hosts.py | 26 ++++++------ nsupdate/management/commands/testuser.py | 6 +-- 4 files changed, 45 insertions(+), 67 deletions(-) diff --git a/nsupdate/management/commands/domains.py b/nsupdate/management/commands/domains.py index c648be2..aee2f20 100644 --- a/nsupdate/management/commands/domains.py +++ b/nsupdate/management/commands/domains.py @@ -4,8 +4,6 @@ dealing with domains (Domain records in our database) import dns.resolver -from optparse import make_option - from django.core.management.base import BaseCommand from django.core.mail import send_mail from django.db import transaction @@ -15,7 +13,6 @@ from nsupdate.main.models import Domain from nsupdate.main.dnstools import FQDN, query_ns, NameServerNotAvailable from nsupdate.utils.mail import translate_for_user, send_mail_to_user - MSG = _("""\ Your domain: %(domain)s (comment: %(comment)s) @@ -68,20 +65,17 @@ def check_dns(domain): class Command(BaseCommand): help = 'deal with domains' - option_list = BaseCommand.option_list + ( - make_option('--check', - action='store_true', - dest='check', - default=False, - help='check whether nameserver for domain is reachable and answers queries', - ), - make_option('--notify-user', - action='store_true', - dest='notify_user', - default=False, - help='notify the user by email when domain gets flagged as unavailable', - ), - ) + def add_arguments(self, parser): + parser.add_argument('--check', + action='store_true', + dest='check', + default=False, + help='check whether nameserver for domain is reachable and answers queries') + parser.add_argument('--notify-user', + action='store_true', + dest='notify_user', + default=False, + help='notify the user by email when domain gets flagged as unavailable') def handle(self, *args, **options): check = options['check'] @@ -105,6 +99,6 @@ class Command(BaseCommand): subject = subject % dict(domain=domain) msg = msg % dict(domain=domain, comment=comment) send_mail_to_user(creator, subject, msg) - msg = "setting unavailable flag for domain %s (created by %s)\n" % (domain, creator, ) + msg = "setting unavailable flag for domain %s (created by %s)\n" % (domain, creator,) self.stdout.write(msg) d.save() diff --git a/nsupdate/management/commands/faults.py b/nsupdate/management/commands/faults.py index beaee5c..9b90b07 100644 --- a/nsupdate/management/commands/faults.py +++ b/nsupdate/management/commands/faults.py @@ -4,8 +4,6 @@ dealing with the fault counters and available/abuse/abuse_blocked flags import traceback -from optparse import make_option - from django.core.management.base import BaseCommand from django.core.mail import send_mail from django.db import transaction @@ -52,63 +50,53 @@ Notes: class Command(BaseCommand): help = 'deal with the faults counters' - option_list = BaseCommand.option_list + ( - make_option('--show-server', + def add_arguments(self, parser): + parser.add_argument('--show-server', action='store_true', dest='show_server', default=False, - help='show server fault counters', - ), - make_option('--show-client', + help='show server fault counters') + parser.add_argument('--show-client', action='store_true', dest='show_client', default=False, - help='show client fault counters', - ), - make_option('--reset-server', + help='show client fault counters') + parser.add_argument('--reset-server', action='store_true', dest='reset_server', default=False, - help='reset the server fault counters of all hosts', - ), - make_option('--reset-client', + help='reset the server fault counters of all hosts') + parser.add_argument('--reset-client', action='store_true', dest='reset_client', default=False, - help='reset the client fault counters of all hosts', - ), - make_option('--reset-abuse', + help='reset the client fault counters of all hosts') + parser.add_argument('--reset-abuse', action='store_true', dest='reset_abuse', default=False, - help='reset the abuse flag (to False) of all hosts', - ), - make_option('--reset-abuse-blocked', + help='reset the abuse flag (to False) of all hosts') + parser.add_argument('--reset-abuse-blocked', action='store_true', dest='reset_abuse_blocked', default=False, - help='reset the abuse_blocked flag (to False) of all hosts', - ), - make_option('--reset-available', + help='reset the abuse_blocked flag (to False) of all hosts') + parser.add_argument('--reset-available', action='store_true', dest='reset_available', default=False, - help='reset the available flag (to True) of all hosts', - ), - make_option('--flag-abuse', + help='reset the available flag (to True) of all hosts') + parser.add_argument('--flag-abuse', action='store', dest='flag_abuse', default=None, type='int', - help='if client faults > N then set abuse flag and reset client faults', - ), - make_option('--notify-user', + help='if client faults > N then set abuse flag and reset client faults') + parser.add_argument('--notify-user', action='store_true', dest='notify_user', default=False, - help='notify the user by email when host gets flagged for abuse', - ), - ) + help='notify the user by email when host gets flagged for abuse') def handle(self, *args, **options): show_client = options['show_client'] diff --git a/nsupdate/management/commands/hosts.py b/nsupdate/management/commands/hosts.py index de1fd45..9dd852e 100644 --- a/nsupdate/management/commands/hosts.py +++ b/nsupdate/management/commands/hosts.py @@ -3,7 +3,6 @@ dealing with hosts (Host records in our database) """ from datetime import datetime -from optparse import make_option from django.core.management.base import BaseCommand from django.db import transaction @@ -132,20 +131,17 @@ def check_staleness(h): class Command(BaseCommand): help = 'deal with hosts' - option_list = BaseCommand.option_list + ( - make_option('--stale-check', - action='store_true', - dest='stale_check', - default=False, - help='check whether the host has been updated recently, increase staleness counter if not', - ), - make_option('--notify-user', - action='store_true', - dest='notify_user', - default=False, - help='notify the user by email when staleness counter increases', - ), - ) + def add_arguments(self, parser): + parser.add_argument('--stale-check', + action='store_true', + dest='stale_check', + default=False, + help='check whether the host has been updated recently, increase staleness counter if not') + parser.add_argument('--notify-user', + action='store_true', + dest='notify_user', + default=False, + help='notify the user by email when staleness counter increases') def handle(self, *args, **options): stale_check = options['stale_check'] diff --git a/nsupdate/management/commands/testuser.py b/nsupdate/management/commands/testuser.py index 158d594..c90c2d4 100644 --- a/nsupdate/management/commands/testuser.py +++ b/nsupdate/management/commands/testuser.py @@ -4,13 +4,13 @@ reinitialize the test user account (and clean up) from django.conf import settings from django.contrib.auth import get_user_model -from django.core.management.base import NoArgsCommand +from django.core.management.base import BaseCommand -class Command(NoArgsCommand): +class Command(BaseCommand): help = 'reinitialize the test user' - def handle_noargs(self, **options): + def handle(self, *args, **options): user_model = get_user_model() try: u = user_model.objects.get(username='test')