Django 1.10: Use add_argument for options in BaseCommand.

This commit is contained in:
Umair Khan
2016-11-03 14:22:19 +05:00
committed by Tim Abbott
parent d3a4fa3e94
commit 682aa1f298
18 changed files with 284 additions and 240 deletions

View File

@@ -6,15 +6,16 @@ import pytz
from optparse import make_option from optparse import make_option
from typing import Any 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 from zerver.lib.statistics import activity_averages_during_day
class Command(BaseCommand): class Command(BaseCommand):
help = "Generate statistics on user activity for a given day." help = "Generate statistics on user activity for a given day."
option_list = BaseCommand.option_list + \ def add_arguments(self, parser):
(make_option('--date', default=None, action='store', # type: (CommandParser) -> None
help="Day to query in format 2013-12-05. Default is yesterday"),) 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): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -4,7 +4,7 @@ from __future__ import print_function
from typing import Any from typing import Any
from optparse import make_option 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.models import Recipient, Message
from zerver.lib.timestamp import timestamp_to_datetime from zerver.lib.timestamp import timestamp_to_datetime
import 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))) logging.info("%15s | %s%%" % (client, round(100. * total_counts[client] / grand_total, 1)))
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + \
(make_option('--verbose', default=False, action='store_true'),)
help = "Compute statistics on MIT Zephyr usage." 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): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None
level = logging.INFO level = logging.INFO

View File

@@ -7,7 +7,7 @@ from typing import Any, Dict
from zerver.lib.statistics import seconds_usage_between from zerver.lib.statistics import seconds_usage_between
from optparse import make_option 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 from zerver.models import UserProfile
import datetime import datetime
from django.utils.timezone import utc 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 By default, if no date is selected 2013-09-10 is used. If no realm is provided, information
is shown for all realms""" is shown for all realms"""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('--realm', action='store'), # type: (CommandParser) -> None
make_option('--date', action='store', default="2013-09-06"), parser.add_argument('--realm', action='store')
make_option('--duration', action='store', default=1, type=int, parser.add_argument('--date', action='store', default="2013-09-06")
help="How many days to show usage information for"), parser.add_argument('--duration', action='store', default=1, type=int,
) help="How many days to show usage information for")
def handle(self, *args, **options): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -5,7 +5,7 @@ from optparse import make_option
from typing import Any 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.lib.actions import create_stream_if_needed, bulk_add_subscriptions
from zerver.models import UserProfile, get_realm, get_user_profile_by_email 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): class Command(BaseCommand):
help = """Add some or all users in a realm to a set of streams.""" help = """Add some or all users in a realm to a set of streams."""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-d', '--domain', # type: (CommandParser) -> None
dest='domain', parser.add_argument(
type='str', '-d', '--domain',
help='The name of the realm in which you are adding people to streams.'), dest='domain',
make_option('-s', '--streams', type=str,
dest='streams', help='The name of the realm in which you are adding people to streams.')
type='str',
help='A comma-separated list of stream names.'), parser.add_argument(
make_option('-u', '--users', '-s', '--streams',
dest='users', dest='streams',
type='str', type=str,
help='A comma-separated list of email addresses.'), help='A comma-separated list of stream names.')
make_option('-a', '--all-users',
dest='all_users', parser.add_argument(
action="store_true", '-u', '--users',
default=False, dest='users',
help='Add all users in this realm to these streams.'), 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): def handle(self, **options):
# type: (**Any) -> None # type: (**Any) -> None

View File

@@ -6,7 +6,7 @@ from typing import Any, Callable, Optional
from zerver.models import get_user_profile_by_id from zerver.models import get_user_profile_by_id
from zerver.lib.rate_limiter import client, max_api_calls, max_api_window 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 django.conf import settings
from optparse import make_option from optparse import make_option
@@ -17,13 +17,13 @@ class Command(BaseCommand):
Usage: ./manage.py [--trim] check_redis""" Usage: ./manage.py [--trim] check_redis"""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-t', '--trim', # type: (CommandParser) -> None
dest='trim', parser.add_argument('-t', '--trim',
default=False, dest='trim',
action='store_true', default=False,
help="Actually trim excess"), action='store_true',
) help="Actually trim excess")
def _check_within_range(self, key, count_func, trim_func=None): def _check_within_range(self, key, count_func, trim_func=None):
# type: (str, Callable[[], int], Optional[Callable[[str, int], None]]) -> None # type: (str, Callable[[], int], Optional[Callable[[str, int], None]]) -> None

View File

@@ -11,7 +11,6 @@ import sys
class Command(BaseCommand): class Command(BaseCommand):
help = """Checks your Zulip Voyager Django configuration for issues.""" help = """Checks your Zulip Voyager Django configuration for issues."""
option_list = BaseCommand.option_list + ()
def handle(self, *args, **options): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None
for (setting_name, default) in settings.REQUIRED_SETTINGS: for (setting_name, default) in settings.REQUIRED_SETTINGS:

View File

@@ -5,7 +5,7 @@ from optparse import make_option
from typing import Any from typing import Any
from django.conf import settings 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.lib.actions import Realm, do_create_realm, set_default_streams
from zerver.models import RealmAlias, can_add_alias, get_realm_by_string_id 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'""" Usage: python manage.py create_realm --string_id=acme --name='Acme'"""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-d', '--domain', # type: (CommandParser) -> None
dest='domain', parser.add_argument('-d', '--domain',
type='str', dest='domain',
help='The domain for the realm.'), type=str,
make_option('-s', '--string_id', help='The domain for the realm.')
dest='string_id',
type='str', parser.add_argument('-s', '--string_id',
help="A short name for the realm. If this installation uses subdomains, this will be used as the realm's subdomain."), dest='string_id',
make_option('-n', '--name', type=str,
dest='name', help="A short name for the realm. If this "
type='str', "installation uses subdomains, this will be "
help='The user-visible name for the realm.'), "used as the realm's subdomain.")
make_option('--corporate',
dest='org_type', parser.add_argument('-n', '--name',
action="store_const", dest='name',
const=Realm.CORPORATE, type=str,
help='Is a corporate org_type'), help='The user-visible name for the realm.')
make_option('--community',
dest='org_type', parser.add_argument('--corporate',
action="store_const", dest='org_type',
const=Realm.COMMUNITY, action="store_const",
default=None, const=Realm.CORPORATE,
help='Is a community org_type. Is the default.'), help='Is a corporate org_type')
make_option('--deployment',
dest='deployment_id', parser.add_argument('--community',
type='int', dest='org_type',
default=None, action="store_const",
help='Optionally, the ID of the deployment you want to associate the realm with.'), 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): def validate_domain(self, domain):
# type: (str) -> None # type: (str) -> None

View File

@@ -4,26 +4,26 @@ from __future__ import print_function
from typing import Any from typing import Any
from optparse import make_option 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 from zerver.models import get_realm, Message, Realm, Stream, Recipient
import datetime import datetime
import time import time
class Command(BaseCommand): 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 + ( parser.add_argument('--since',
make_option('--domain', dest='since',
dest='domain', type=int,
type='str', default=default_cutoff,
help='The domain whose public streams you want to dump.'), help='The time in epoch since from which to start the dump.')
make_option('--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): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -4,7 +4,7 @@ from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management import call_command 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.db import connection
from django.conf import settings 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] <export path name> [<export path name>...]""" Usage: python2.7 manage.py import [--destroy-rebuild-database] [--import-into-nonempty] <export path name> [<export path name>...]"""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('--destroy-rebuild-database', # type: (CommandParser) -> None
dest='destroy_rebuild_database', parser.add_argument('--destroy-rebuild-database',
default=False, dest='destroy_rebuild_database',
action="store_true", default=False,
help='Destroys and rebuilds the databases prior to import.'), action="store_true",
make_option('--import-into-nonempty', help='Destroys and rebuilds the databases prior to import.')
dest='import_into_nonempty',
default=False, parser.add_argument('--import-into-nonempty',
action="store_true", dest='import_into_nonempty',
help='Import into an existing nonempty database.'), default=False,
) action="store_true",
help='Import into an existing nonempty database.')
def new_instance_check(self, model): def new_instance_check(self, model):
# type: (Model) -> None # type: (Model) -> None

View File

@@ -6,7 +6,7 @@ from typing import Any
from argparse import ArgumentParser from argparse import ArgumentParser
from optparse import make_option 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.lib.actions import bulk_remove_subscriptions
from zerver.models import Realm, UserProfile, get_realm, get_stream, \ 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): class Command(BaseCommand):
help = """Remove some or all users in a realm from a stream.""" help = """Remove some or all users in a realm from a stream."""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-d', '--domain', # type: (CommandParser) -> None
dest='domain', parser.add_argument('-d', '--domain',
type='str', dest='domain',
help='The name of the realm in which you are removing people.'), type=str,
make_option('-s', '--stream', help='The name of the realm in which you are '
dest='stream', 'removing people.')
type='str',
help='A stream name.'), parser.add_argument('-s', '--stream',
make_option('-u', '--users', dest='stream',
dest='users', type=str,
type='str', help='A stream name.')
help='A comma-separated list of email addresses.'),
make_option('-a', '--all-users', parser.add_argument('-u', '--users',
dest='all_users', dest='users',
action="store_true", type=str,
default=False, help='A comma-separated list of email addresses.')
help='Remove all users in this realm from this stream.'),
) 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): def handle(self, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -13,7 +13,7 @@ settings.RUNNING_INSIDE_TORNADO = True
from zerver.lib.tornado_ioloop_logging import instrument_tornado_ioloop from zerver.lib.tornado_ioloop_logging import instrument_tornado_ioloop
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 django.http import HttpRequest, HttpResponse
from optparse import make_option from optparse import make_option
import sys import sys
@@ -53,16 +53,21 @@ def handle_callback_exception(callback):
app_log.error("Exception in callback %r", callback, exc_info=True) app_log.error("Exception in callback %r", callback, exc_info=True)
class Command(BaseCommand): 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." 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): def handle(self, addrport, **options):
# type: (str, **bool) -> None # type: (str, **bool) -> None

View File

@@ -9,7 +9,7 @@ from optparse import make_option
from django.test import Client from django.test import Client
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand, CommandParser
class Command(BaseCommand): class Command(BaseCommand):
@@ -22,16 +22,19 @@ Example:
""" """
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-f', '--fixture', # type: (CommandParser) -> None
dest='fixture', parser.add_argument('-f', '--fixture',
type='str', dest='fixture',
help='The path to the fixture you\'d like to send into Zulip'), type=str,
make_option('-u', '--url', help='The path to the fixture you\'d like to send '
dest='url', 'into Zulip')
type='str',
help='The url on your Zulip server that you want to post the fixture to'), 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): def handle(self, **options):
# type: (*Any, **str) -> None # type: (*Any, **str) -> None

View File

@@ -3,7 +3,7 @@ from __future__ import print_function
from typing import Any 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.models import get_realm
from zerver.lib.actions import set_default_streams 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= python manage.py set_default_streams --domain=foo.com --streams=
""" """
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-d', '--domain', # type: (CommandParser) -> None
dest='domain', parser.add_argument('-d', '--domain',
type='str', dest='domain',
help='The name of the existing realm to which to attach default streams.'), type=str,
make_option('-s', '--streams', help='The name of the existing realm to which to '
dest='streams', 'attach default streams.')
type='str',
help='A comma-separated list of stream names.'), parser.add_argument('-s', '--streams',
) dest='streams',
type=str,
help='A comma-separated list of stream names.')
def handle(self, **options): def handle(self, **options):
# type: (*Any, **str) -> None # type: (*Any, **str) -> None

View File

@@ -7,7 +7,7 @@ from optparse import make_option
import logging import logging
import sys import sys
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand, CommandParser
from zerver.lib import utils from zerver.lib import utils
from zerver.models import UserMessage, get_user_profile_by_email 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 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.""" Expects a comma-delimited list of user message ids via stdin, and an EOF to terminate."""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-r', '--for-real', # type: (CommandParser) -> None
dest='for_real', parser.add_argument('-r', '--for-real',
action='store_true', dest='for_real',
default=False, action='store_true',
help="Actually change message flags. Default is a dry run."), default=False,
make_option('-f', '--flag', help="Actually change message flags. Default is a dry run.")
dest='flag',
type='string', parser.add_argument('-f', '--flag',
help="The flag to add of remove"), dest='flag',
make_option('-o', '--op', type=str,
dest='op', help="The flag to add of remove")
type='string',
help="The operation to do: 'add' or 'remove'"), parser.add_argument('-o', '--op',
make_option('-u', '--until', dest='op',
dest='all_until', type=str,
type='string', help="The operation to do: 'add' or 'remove'")
help="Mark all messages <= specific usermessage id"),
make_option('-m', '--email', parser.add_argument('-u', '--until',
dest='email', dest='all_until',
type='string', type=str,
help="Email to set messages for"), 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): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -5,7 +5,7 @@ from typing import Any
from optparse import make_option 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.lib.actions import do_change_enable_digest_emails
from zerver.models import Realm, UserProfile, get_realm, get_user_profile_by_email 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): class Command(BaseCommand):
help = """Turn off digests for a domain or specified set of email addresses.""" help = """Turn off digests for a domain or specified set of email addresses."""
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-d', '--domain', # type: (CommandParser) -> None
dest='domain', parser.add_argument('-d', '--domain',
type='str', dest='domain',
help='Turn off digests for all users in this domain.'), type=str,
make_option('-u', '--users', help='Turn off digests for all users in this domain.')
dest='users',
type='str', parser.add_argument('-u', '--users',
help='Turn off digests for this comma-separated list of email addresses.'), dest='users',
) type=str,
help='Turn off digests for this comma-separated '
'list of email addresses.')
def handle(self, **options): def handle(self, **options):
# type: (**str) -> None # type: (**str) -> None

View File

@@ -5,7 +5,7 @@ from optparse import make_option
import sys import sys
from typing import Any 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.models import get_realm
from zerver.lib.create_user import random_api_key from zerver.lib.create_user import random_api_key
@@ -16,21 +16,18 @@ from zilencer.models import Deployment
class Command(BaseCommand): class Command(BaseCommand):
help = """Create a deployment and accompanying realm.""" help = """Create a deployment and accompanying realm."""
option_list = CreateRealm.option_list + ( def add_arguments(self, parser):
make_option('--no-realm', # type: (CommandParser) -> None
dest='no_realm', parser.add_argument('--no-realm',
action='store_true', dest='no_realm',
default=False, action='store_true',
help='Do not create a new realm; associate with an existing one.' + \ default=False,
' In this case, only the domain and URLs need to be specified.'), help='Do not create a new realm; associate with '
make_option('-a', '--api-url', 'an existing one. In this case, only the '
dest='api', 'domain and URLs need to be specified.')
type='str'),
make_option('-w', '--web-url',
dest='web',
type='str'),
) 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): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None

View File

@@ -2,7 +2,7 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function 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.utils.timezone import now
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
@@ -55,62 +55,72 @@ def create_streams(realms, realm, stream_list):
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate a test database" help = "Populate a test database"
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('-n', '--num-messages', # type: (CommandParser) -> None
parser.add_argument('-n', '--num-messages',
dest='num_messages', dest='num_messages',
type='int', type=int,
default=600, default=600,
help='The number of messages to create.'), help='The number of messages to create.')
make_option('--extra-users',
parser.add_argument('--extra-users',
dest='extra_users', dest='extra_users',
type='int', type=int,
default=0, default=0,
help='The number of extra users to create'), help='The number of extra users to create')
make_option('--huddles',
parser.add_argument('--huddles',
dest='num_huddles', dest='num_huddles',
type='int', type=int,
default=3, default=3,
help='The number of huddles to create.'), help='The number of huddles to create.')
make_option('--personals',
parser.add_argument('--personals',
dest='num_personals', dest='num_personals',
type='int', type=int,
default=6, default=6,
help='The number of personal pairs to create.'), help='The number of personal pairs to create.')
make_option('--threads',
parser.add_argument('--threads',
dest='threads', dest='threads',
type='int', type=int,
default=10, default=10,
help='The number of threads to use.'), help='The number of threads to use.')
make_option('--percent-huddles',
parser.add_argument('--percent-huddles',
dest='percent_huddles', dest='percent_huddles',
type='float', type=float,
default=15, default=15,
help='The percent of messages to be huddles.'), help='The percent of messages to be huddles.')
make_option('--percent-personals',
parser.add_argument('--percent-personals',
dest='percent_personals', dest='percent_personals',
type='float', type=float,
default=15, default=15,
help='The percent of messages to be personals.'), help='The percent of messages to be personals.')
make_option('--stickyness',
parser.add_argument('--stickyness',
dest='stickyness', dest='stickyness',
type='float', type=float,
default=20, default=20,
help='The percent of messages to repeat recent folks.'), help='The percent of messages to repeat recent folks.')
make_option('--nodelete',
parser.add_argument('--nodelete',
action="store_false", action="store_false",
default=True, default=True,
dest='delete', dest='delete',
help='Whether to delete all the existing messages.'), help='Whether to delete all the existing messages.')
make_option('--test-suite',
parser.add_argument('--test-suite',
default=False, default=False,
action="store_true", action="store_true",
help='Whether to delete all the existing messages.'), help='Whether to delete all the existing messages.')
make_option('--replay-old-messages',
parser.add_argument('--replay-old-messages',
action="store_true", action="store_true",
default=False, default=False,
dest='replay_old_messages', 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): def handle(self, **options):
# type: (**Any) -> None # type: (**Any) -> None

View File

@@ -3,7 +3,7 @@ from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from optparse import make_option 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.models import get_user_profile_by_email, UserMessage
from zerver.views.messages import get_old_messages_backend from zerver.views.messages import get_old_messages_backend
import cProfile import cProfile
@@ -50,9 +50,9 @@ def profile_request(request):
return ret return ret
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('--email', action='store'), # type: (CommandParser) -> None
) parser.add_argument('--email', action='store')
def handle(self, *args, **options): def handle(self, *args, **options):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None