From 682aa1f2981ddce4927a7926d23c98d6094b325c Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 3 Nov 2016 14:22:19 +0500 Subject: [PATCH] Django 1.10: Use add_argument for options in BaseCommand. --- .../commands/active_user_stats_by_day.py | 9 ++- analytics/management/commands/analyze_mit.py | 9 ++- .../commands/analyze_user_activity.py | 14 ++-- .../commands/add_users_to_streams.py | 47 +++++++----- zerver/management/commands/check_redis.py | 16 ++-- zerver/management/commands/checkconfig.py | 1 - zerver/management/commands/create_realm.py | 70 +++++++++-------- zerver/management/commands/dump_messages.py | 26 +++---- zerver/management/commands/import.py | 27 +++---- .../commands/remove_users_from_stream.py | 44 ++++++----- zerver/management/commands/runtornado.py | 25 +++--- .../commands/send_webhook_fixture_message.py | 25 +++--- .../commands/set_default_streams.py | 24 +++--- .../management/commands/set_message_flags.py | 52 +++++++------ .../management/commands/turn_off_digests.py | 24 +++--- .../management/commands/create_deployment.py | 27 +++---- zilencer/management/commands/populate_db.py | 76 +++++++++++-------- .../management/commands/profile_request.py | 8 +- 18 files changed, 284 insertions(+), 240 deletions(-) diff --git a/analytics/management/commands/active_user_stats_by_day.py b/analytics/management/commands/active_user_stats_by_day.py index 016c0bb0ad..9776feec8e 100644 --- a/analytics/management/commands/active_user_stats_by_day.py +++ b/analytics/management/commands/active_user_stats_by_day.py @@ -6,15 +6,16 @@ import pytz from optparse import make_option from typing import Any -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib.statistics import activity_averages_during_day class Command(BaseCommand): help = "Generate statistics on user activity for a given day." - option_list = BaseCommand.option_list + \ - (make_option('--date', default=None, action='store', - help="Day to query in format 2013-12-05. Default is yesterday"),) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--date', default=None, action='store', + help="Day to query in format 2013-12-05. Default is yesterday") def handle(self, *args, **options): # type: (*Any, **Any) -> None diff --git a/analytics/management/commands/analyze_mit.py b/analytics/management/commands/analyze_mit.py index 541cc44ffd..698c187087 100644 --- a/analytics/management/commands/analyze_mit.py +++ b/analytics/management/commands/analyze_mit.py @@ -4,7 +4,7 @@ from __future__ import print_function from typing import Any from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import Recipient, Message from zerver.lib.timestamp import timestamp_to_datetime import datetime @@ -73,11 +73,12 @@ def compute_stats(log_level): logging.info("%15s | %s%%" % (client, round(100. * total_counts[client] / grand_total, 1))) class Command(BaseCommand): - option_list = BaseCommand.option_list + \ - (make_option('--verbose', default=False, action='store_true'),) - help = "Compute statistics on MIT Zephyr usage." + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--verbose', default=False, action='store_true') + def handle(self, *args, **options): # type: (*Any, **Any) -> None level = logging.INFO diff --git a/analytics/management/commands/analyze_user_activity.py b/analytics/management/commands/analyze_user_activity.py index 1d177e8c4a..316d96a8cf 100644 --- a/analytics/management/commands/analyze_user_activity.py +++ b/analytics/management/commands/analyze_user_activity.py @@ -7,7 +7,7 @@ from typing import Any, Dict from zerver.lib.statistics import seconds_usage_between from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import UserProfile import datetime from django.utils.timezone import utc @@ -52,12 +52,12 @@ Usage: python manage.py analyze_user_activity [--realm=zulip.com] [--date=2013-0 By default, if no date is selected 2013-09-10 is used. If no realm is provided, information is shown for all realms""" - option_list = BaseCommand.option_list + ( - make_option('--realm', action='store'), - make_option('--date', action='store', default="2013-09-06"), - make_option('--duration', action='store', default=1, type=int, - help="How many days to show usage information for"), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--realm', action='store') + parser.add_argument('--date', action='store', default="2013-09-06") + parser.add_argument('--duration', action='store', default=1, type=int, + help="How many days to show usage information for") def handle(self, *args, **options): # type: (*Any, **Any) -> None diff --git a/zerver/management/commands/add_users_to_streams.py b/zerver/management/commands/add_users_to_streams.py index 676972b1de..720cf82c4f 100644 --- a/zerver/management/commands/add_users_to_streams.py +++ b/zerver/management/commands/add_users_to_streams.py @@ -5,7 +5,7 @@ from optparse import make_option from typing import Any -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib.actions import create_stream_if_needed, bulk_add_subscriptions from zerver.models import UserProfile, get_realm, get_user_profile_by_email @@ -13,25 +13,32 @@ from zerver.models import UserProfile, get_realm, get_user_profile_by_email class Command(BaseCommand): help = """Add some or all users in a realm to a set of streams.""" - option_list = BaseCommand.option_list + ( - make_option('-d', '--domain', - dest='domain', - type='str', - help='The name of the realm in which you are adding people to streams.'), - make_option('-s', '--streams', - dest='streams', - type='str', - help='A comma-separated list of stream names.'), - make_option('-u', '--users', - dest='users', - type='str', - help='A comma-separated list of email addresses.'), - make_option('-a', '--all-users', - dest='all_users', - action="store_true", - default=False, - help='Add all users in this realm to these streams.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument( + '-d', '--domain', + dest='domain', + type=str, + help='The name of the realm in which you are adding people to streams.') + + parser.add_argument( + '-s', '--streams', + dest='streams', + type=str, + help='A comma-separated list of stream names.') + + parser.add_argument( + '-u', '--users', + dest='users', + type=str, + help='A comma-separated list of email addresses.') + + parser.add_argument( + '-a', '--all-users', + dest='all_users', + action="store_true", + default=False, + help='Add all users in this realm to these streams.') def handle(self, **options): # type: (**Any) -> None diff --git a/zerver/management/commands/check_redis.py b/zerver/management/commands/check_redis.py index a40559ba79..872d1979fb 100644 --- a/zerver/management/commands/check_redis.py +++ b/zerver/management/commands/check_redis.py @@ -6,7 +6,7 @@ from typing import Any, Callable, Optional from zerver.models import get_user_profile_by_id from zerver.lib.rate_limiter import client, max_api_calls, max_api_window -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from django.conf import settings from optparse import make_option @@ -17,13 +17,13 @@ class Command(BaseCommand): Usage: ./manage.py [--trim] check_redis""" - option_list = BaseCommand.option_list + ( - make_option('-t', '--trim', - dest='trim', - default=False, - action='store_true', - help="Actually trim excess"), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-t', '--trim', + dest='trim', + default=False, + action='store_true', + help="Actually trim excess") def _check_within_range(self, key, count_func, trim_func=None): # type: (str, Callable[[], int], Optional[Callable[[str, int], None]]) -> None diff --git a/zerver/management/commands/checkconfig.py b/zerver/management/commands/checkconfig.py index 0d3d3d53f5..f4aba97bc5 100644 --- a/zerver/management/commands/checkconfig.py +++ b/zerver/management/commands/checkconfig.py @@ -11,7 +11,6 @@ import sys class Command(BaseCommand): help = """Checks your Zulip Voyager Django configuration for issues.""" - option_list = BaseCommand.option_list + () def handle(self, *args, **options): # type: (*Any, **Any) -> None for (setting_name, default) in settings.REQUIRED_SETTINGS: diff --git a/zerver/management/commands/create_realm.py b/zerver/management/commands/create_realm.py index 1d8a44efbc..652ecf902b 100644 --- a/zerver/management/commands/create_realm.py +++ b/zerver/management/commands/create_realm.py @@ -5,7 +5,7 @@ from optparse import make_option from typing import Any from django.conf import settings -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib.actions import Realm, do_create_realm, set_default_streams from zerver.models import RealmAlias, can_add_alias, get_realm_by_string_id @@ -20,36 +20,44 @@ class Command(BaseCommand): Usage: python manage.py create_realm --string_id=acme --name='Acme'""" - option_list = BaseCommand.option_list + ( - make_option('-d', '--domain', - dest='domain', - type='str', - help='The domain for the realm.'), - make_option('-s', '--string_id', - dest='string_id', - type='str', - help="A short name for the realm. If this installation uses subdomains, this will be used as the realm's subdomain."), - make_option('-n', '--name', - dest='name', - type='str', - help='The user-visible name for the realm.'), - make_option('--corporate', - dest='org_type', - action="store_const", - const=Realm.CORPORATE, - help='Is a corporate org_type'), - make_option('--community', - dest='org_type', - action="store_const", - const=Realm.COMMUNITY, - default=None, - help='Is a community org_type. Is the default.'), - make_option('--deployment', - dest='deployment_id', - type='int', - default=None, - help='Optionally, the ID of the deployment you want to associate the realm with.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-d', '--domain', + dest='domain', + type=str, + help='The domain for the realm.') + + parser.add_argument('-s', '--string_id', + dest='string_id', + type=str, + help="A short name for the realm. If this " + "installation uses subdomains, this will be " + "used as the realm's subdomain.") + + parser.add_argument('-n', '--name', + dest='name', + type=str, + help='The user-visible name for the realm.') + + parser.add_argument('--corporate', + dest='org_type', + action="store_const", + const=Realm.CORPORATE, + help='Is a corporate org_type') + + parser.add_argument('--community', + dest='org_type', + action="store_const", + const=Realm.COMMUNITY, + default=None, + help='Is a community org_type. Is the default.') + + parser.add_argument('--deployment', + dest='deployment_id', + type=int, + default=None, + help='Optionally, the ID of the deployment you ' + 'want to associate the realm with.') def validate_domain(self, domain): # type: (str) -> None diff --git a/zerver/management/commands/dump_messages.py b/zerver/management/commands/dump_messages.py index 00e644ca56..64265a22ff 100644 --- a/zerver/management/commands/dump_messages.py +++ b/zerver/management/commands/dump_messages.py @@ -4,26 +4,26 @@ from __future__ import print_function from typing import Any from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import get_realm, Message, Realm, Stream, Recipient import datetime import time class Command(BaseCommand): - default_cutoff = time.time() - 60 * 60 * 24 * 30 # 30 days. + def add_arguments(self, parser): + # type: (CommandParser) -> None + default_cutoff = time.time() - 60 * 60 * 24 * 30 # 30 days. + parser.add_argument('--domain', + dest='domain', + type=str, + help='The domain whose public streams you want to dump.') - option_list = BaseCommand.option_list + ( - make_option('--domain', - dest='domain', - type='str', - help='The domain whose public streams you want to dump.'), - make_option('--since', - dest='since', - type='int', - default=default_cutoff, - help='The time in epoch since from which to start the dump.') - ) + parser.add_argument('--since', + dest='since', + type=int, + default=default_cutoff, + help='The time in epoch since from which to start the dump.') def handle(self, *args, **options): # type: (*Any, **Any) -> None diff --git a/zerver/management/commands/import.py b/zerver/management/commands/import.py index e7be76e553..6a85c3d83b 100644 --- a/zerver/management/commands/import.py +++ b/zerver/management/commands/import.py @@ -4,7 +4,7 @@ from __future__ import print_function from optparse import make_option from django.core.management import call_command -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from django.db import connection from django.conf import settings @@ -29,18 +29,19 @@ import a database dump from one or more JSON files. Usage: python2.7 manage.py import [--destroy-rebuild-database] [--import-into-nonempty] [...]""" - option_list = BaseCommand.option_list + ( - make_option('--destroy-rebuild-database', - dest='destroy_rebuild_database', - default=False, - action="store_true", - help='Destroys and rebuilds the databases prior to import.'), - make_option('--import-into-nonempty', - dest='import_into_nonempty', - default=False, - action="store_true", - help='Import into an existing nonempty database.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--destroy-rebuild-database', + dest='destroy_rebuild_database', + default=False, + action="store_true", + help='Destroys and rebuilds the databases prior to import.') + + parser.add_argument('--import-into-nonempty', + dest='import_into_nonempty', + default=False, + action="store_true", + help='Import into an existing nonempty database.') def new_instance_check(self, model): # type: (Model) -> None diff --git a/zerver/management/commands/remove_users_from_stream.py b/zerver/management/commands/remove_users_from_stream.py index de9f89aeb4..323dfade12 100644 --- a/zerver/management/commands/remove_users_from_stream.py +++ b/zerver/management/commands/remove_users_from_stream.py @@ -6,7 +6,7 @@ from typing import Any from argparse import ArgumentParser from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib.actions import bulk_remove_subscriptions from zerver.models import Realm, UserProfile, get_realm, get_stream, \ @@ -15,25 +15,29 @@ from zerver.models import Realm, UserProfile, get_realm, get_stream, \ class Command(BaseCommand): help = """Remove some or all users in a realm from a stream.""" - option_list = BaseCommand.option_list + ( - make_option('-d', '--domain', - dest='domain', - type='str', - help='The name of the realm in which you are removing people.'), - make_option('-s', '--stream', - dest='stream', - type='str', - help='A stream name.'), - make_option('-u', '--users', - dest='users', - type='str', - help='A comma-separated list of email addresses.'), - make_option('-a', '--all-users', - dest='all_users', - action="store_true", - default=False, - help='Remove all users in this realm from this stream.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-d', '--domain', + dest='domain', + type=str, + help='The name of the realm in which you are ' + 'removing people.') + + parser.add_argument('-s', '--stream', + dest='stream', + type=str, + help='A stream name.') + + parser.add_argument('-u', '--users', + dest='users', + type=str, + help='A comma-separated list of email addresses.') + + parser.add_argument('-a', '--all-users', + dest='all_users', + action="store_true", + default=False, + help='Remove all users in this realm from this stream.') def handle(self, **options): # type: (*Any, **Any) -> None diff --git a/zerver/management/commands/runtornado.py b/zerver/management/commands/runtornado.py index fe022fc3a7..9911c44493 100644 --- a/zerver/management/commands/runtornado.py +++ b/zerver/management/commands/runtornado.py @@ -13,7 +13,7 @@ settings.RUNNING_INSIDE_TORNADO = True from zerver.lib.tornado_ioloop_logging import instrument_tornado_ioloop instrument_tornado_ioloop() -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand, CommandError, CommandParser from django.http import HttpRequest, HttpResponse from optparse import make_option import sys @@ -53,16 +53,21 @@ def handle_callback_exception(callback): app_log.error("Exception in callback %r", callback, exc_info=True) class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--nokeepalive', action='store_true', - dest='no_keep_alive', default=False, - help="Tells Tornado to NOT keep alive http connections."), - make_option('--noxheaders', action='store_false', - dest='xheaders', default=True, - help="Tells Tornado to NOT override remote IP with X-Real-IP."), - ) help = "Starts a Tornado Web server wrapping Django." - args = '[optional port number or ipaddr:port]\n (use multiple ports to start multiple servers)' + + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('addrport', nargs="?", type=str, + help='[optional port number or ipaddr:port]\n ' + '(use multiple ports to start multiple servers)') + + parser.add_argument('--nokeepalive', action='store_true', + dest='no_keep_alive', default=False, + help="Tells Tornado to NOT keep alive http connections.") + + parser.add_argument('--noxheaders', action='store_false', + dest='xheaders', default=True, + help="Tells Tornado to NOT override remote IP with X-Real-IP.") def handle(self, addrport, **options): # type: (str, **bool) -> None diff --git a/zerver/management/commands/send_webhook_fixture_message.py b/zerver/management/commands/send_webhook_fixture_message.py index 636dffb87d..7784698524 100644 --- a/zerver/management/commands/send_webhook_fixture_message.py +++ b/zerver/management/commands/send_webhook_fixture_message.py @@ -9,7 +9,7 @@ from optparse import make_option from django.test import Client from django.conf import settings -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser class Command(BaseCommand): @@ -22,16 +22,19 @@ Example: """ - option_list = BaseCommand.option_list + ( - make_option('-f', '--fixture', - dest='fixture', - type='str', - help='The path to the fixture you\'d like to send into Zulip'), - make_option('-u', '--url', - dest='url', - type='str', - help='The url on your Zulip server that you want to post the fixture to'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-f', '--fixture', + dest='fixture', + type=str, + help='The path to the fixture you\'d like to send ' + 'into Zulip') + + parser.add_argument('-u', '--url', + dest='url', + type=str, + help='The url on your Zulip server that you want ' + 'to post the fixture to') def handle(self, **options): # type: (*Any, **str) -> None diff --git a/zerver/management/commands/set_default_streams.py b/zerver/management/commands/set_default_streams.py index 277355c13d..05574bd307 100644 --- a/zerver/management/commands/set_default_streams.py +++ b/zerver/management/commands/set_default_streams.py @@ -3,7 +3,7 @@ from __future__ import print_function from typing import Any -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import get_realm from zerver.lib.actions import set_default_streams @@ -26,16 +26,18 @@ python manage.py set_default_streams --domain=foo.com --streams="foo,bar,baz wit python manage.py set_default_streams --domain=foo.com --streams= """ - option_list = BaseCommand.option_list + ( - make_option('-d', '--domain', - dest='domain', - type='str', - help='The name of the existing realm to which to attach default streams.'), - make_option('-s', '--streams', - dest='streams', - type='str', - help='A comma-separated list of stream names.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-d', '--domain', + dest='domain', + type=str, + help='The name of the existing realm to which to ' + 'attach default streams.') + + parser.add_argument('-s', '--streams', + dest='streams', + type=str, + help='A comma-separated list of stream names.') def handle(self, **options): # type: (*Any, **str) -> None diff --git a/zerver/management/commands/set_message_flags.py b/zerver/management/commands/set_message_flags.py index f04d79abb8..7913942340 100644 --- a/zerver/management/commands/set_message_flags.py +++ b/zerver/management/commands/set_message_flags.py @@ -7,7 +7,7 @@ from optparse import make_option import logging import sys -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib import utils from zerver.models import UserMessage, get_user_profile_by_email @@ -18,29 +18,33 @@ class Command(BaseCommand): help = """Sets user message flags. Used internally by actions.py. Marks all Expects a comma-delimited list of user message ids via stdin, and an EOF to terminate.""" - option_list = BaseCommand.option_list + ( - make_option('-r', '--for-real', - dest='for_real', - action='store_true', - default=False, - help="Actually change message flags. Default is a dry run."), - make_option('-f', '--flag', - dest='flag', - type='string', - help="The flag to add of remove"), - make_option('-o', '--op', - dest='op', - type='string', - help="The operation to do: 'add' or 'remove'"), - make_option('-u', '--until', - dest='all_until', - type='string', - help="Mark all messages <= specific usermessage id"), - make_option('-m', '--email', - dest='email', - type='string', - help="Email to set messages for"), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-r', '--for-real', + dest='for_real', + action='store_true', + default=False, + help="Actually change message flags. Default is a dry run.") + + parser.add_argument('-f', '--flag', + dest='flag', + type=str, + help="The flag to add of remove") + + parser.add_argument('-o', '--op', + dest='op', + type=str, + help="The operation to do: 'add' or 'remove'") + + parser.add_argument('-u', '--until', + dest='all_until', + type=str, + help="Mark all messages <= specific usermessage id") + + parser.add_argument('-m', '--email', + dest='email', + type=str, + help="Email to set messages for") def handle(self, *args, **options): # type: (*Any, **Any) -> None diff --git a/zerver/management/commands/turn_off_digests.py b/zerver/management/commands/turn_off_digests.py index bb7ba083fa..e15042350a 100644 --- a/zerver/management/commands/turn_off_digests.py +++ b/zerver/management/commands/turn_off_digests.py @@ -5,7 +5,7 @@ from typing import Any from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.lib.actions import do_change_enable_digest_emails from zerver.models import Realm, UserProfile, get_realm, get_user_profile_by_email @@ -13,16 +13,18 @@ from zerver.models import Realm, UserProfile, get_realm, get_user_profile_by_ema class Command(BaseCommand): help = """Turn off digests for a domain or specified set of email addresses.""" - option_list = BaseCommand.option_list + ( - make_option('-d', '--domain', - dest='domain', - type='str', - help='Turn off digests for all users in this domain.'), - make_option('-u', '--users', - dest='users', - type='str', - help='Turn off digests for this comma-separated list of email addresses.'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-d', '--domain', + dest='domain', + type=str, + help='Turn off digests for all users in this domain.') + + parser.add_argument('-u', '--users', + dest='users', + type=str, + help='Turn off digests for this comma-separated ' + 'list of email addresses.') def handle(self, **options): # type: (**str) -> None diff --git a/zilencer/management/commands/create_deployment.py b/zilencer/management/commands/create_deployment.py index ee09c20367..e631364a85 100644 --- a/zilencer/management/commands/create_deployment.py +++ b/zilencer/management/commands/create_deployment.py @@ -5,7 +5,7 @@ from optparse import make_option import sys from typing import Any -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import get_realm from zerver.lib.create_user import random_api_key @@ -16,21 +16,18 @@ from zilencer.models import Deployment class Command(BaseCommand): help = """Create a deployment and accompanying realm.""" - option_list = CreateRealm.option_list + ( - make_option('--no-realm', - dest='no_realm', - action='store_true', - default=False, - help='Do not create a new realm; associate with an existing one.' + \ - ' In this case, only the domain and URLs need to be specified.'), - make_option('-a', '--api-url', - dest='api', - type='str'), - make_option('-w', '--web-url', - dest='web', - type='str'), + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--no-realm', + dest='no_realm', + action='store_true', + default=False, + help='Do not create a new realm; associate with ' + 'an existing one. In this case, only the ' + 'domain and URLs need to be specified.') - ) + parser.add_argument('-a', '--api-url', dest='api', type=str) + parser.add_argument('-w', '--web-url', dest='web', type=str) def handle(self, *args, **options): # type: (*Any, **Any) -> None diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 8bfe187d1f..5edb3ebf6f 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from django.utils.timezone import now from django.contrib.sites.models import Site @@ -55,62 +55,72 @@ def create_streams(realms, realm, stream_list): class Command(BaseCommand): help = "Populate a test database" - option_list = BaseCommand.option_list + ( - make_option('-n', '--num-messages', + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('-n', '--num-messages', dest='num_messages', - type='int', + type=int, default=600, - help='The number of messages to create.'), - make_option('--extra-users', + help='The number of messages to create.') + + parser.add_argument('--extra-users', dest='extra_users', - type='int', + type=int, default=0, - help='The number of extra users to create'), - make_option('--huddles', + help='The number of extra users to create') + + parser.add_argument('--huddles', dest='num_huddles', - type='int', + type=int, default=3, - help='The number of huddles to create.'), - make_option('--personals', + help='The number of huddles to create.') + + parser.add_argument('--personals', dest='num_personals', - type='int', + type=int, default=6, - help='The number of personal pairs to create.'), - make_option('--threads', + help='The number of personal pairs to create.') + + parser.add_argument('--threads', dest='threads', - type='int', + type=int, default=10, - help='The number of threads to use.'), - make_option('--percent-huddles', + help='The number of threads to use.') + + parser.add_argument('--percent-huddles', dest='percent_huddles', - type='float', + type=float, default=15, - help='The percent of messages to be huddles.'), - make_option('--percent-personals', + help='The percent of messages to be huddles.') + + parser.add_argument('--percent-personals', dest='percent_personals', - type='float', + type=float, default=15, - help='The percent of messages to be personals.'), - make_option('--stickyness', + help='The percent of messages to be personals.') + + parser.add_argument('--stickyness', dest='stickyness', - type='float', + type=float, default=20, - help='The percent of messages to repeat recent folks.'), - make_option('--nodelete', + help='The percent of messages to repeat recent folks.') + + parser.add_argument('--nodelete', action="store_false", default=True, dest='delete', - help='Whether to delete all the existing messages.'), - make_option('--test-suite', + help='Whether to delete all the existing messages.') + + parser.add_argument('--test-suite', default=False, action="store_true", - help='Whether to delete all the existing messages.'), - make_option('--replay-old-messages', + help='Whether to delete all the existing messages.') + + parser.add_argument('--replay-old-messages', action="store_true", default=False, dest='replay_old_messages', - help='Whether to replace the log of old messages.'), - ) + help='Whether to replace the log of old messages.') def handle(self, **options): # type: (**Any) -> None diff --git a/zilencer/management/commands/profile_request.py b/zilencer/management/commands/profile_request.py index 3224e47846..1993f57107 100644 --- a/zilencer/management/commands/profile_request.py +++ b/zilencer/management/commands/profile_request.py @@ -3,7 +3,7 @@ from typing import Any, Dict from django.http import HttpRequest, HttpResponse from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandParser from zerver.models import get_user_profile_by_email, UserMessage from zerver.views.messages import get_old_messages_backend import cProfile @@ -50,9 +50,9 @@ def profile_request(request): return ret class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--email', action='store'), - ) + def add_arguments(self, parser): + # type: (CommandParser) -> None + parser.add_argument('--email', action='store') def handle(self, *args, **options): # type: (*Any, **Any) -> None