<commit_before># Library code for use in management commands
from argparse import SUPPRESS, ArgumentParser, RawTextHelpFormatter
from typing import Any, Dict, List, Optional

from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned
from django.core.management.base import BaseCommand, CommandError, CommandParser

from zerver.models import Client, Realm, UserProfile, get_client


def is_integer_string(val: str) -> bool:
    try:
        int(val)
        return True
    except ValueError:
        return False


def check_config() -> None:
    for (setting_name, default) in settings.REQUIRED_SETTINGS:
        # if required setting is the same as default OR is not found in settings,
        # throw error to add/set that setting in config
        try:
            if settings.__getattr__(setting_name) != default:
                continue
        except AttributeError:
            pass

        raise CommandError(f"Error: You must set {setting_name} in /etc/zulip/settings.py.")


class ZulipBaseCommand(BaseCommand):

    # Fix support for multi-line usage
    def create_parser(self, prog_name: str, subcommand: str, **kwargs: Any) -> CommandParser:
        parser = super().create_parser(prog_name, subcommand, **kwargs)
        parser.formatter_class = RawTextHelpFormatter
        return parser

    def add_realm_args(
        self, parser: ArgumentParser, *, required: bool = False, help: Optional[str] = None
    ) -> None:
        if help is None:
            help = """The numeric or string ID (subdomain) of the Zulip organization to modify.
You can use the command list_realms to find ID of the realms in this server."""

        parser.add_argument("-r", "--realm", dest="realm_id", required=required, help=help)

    def add_create_user_args(self, parser: ArgumentParser) -> None:
        parser.add_argument(
            "email",
            metavar="<email>",
            nargs="?",
            default=SUPPRESS,
            help="email address of new user",
        )
        parser.add_argument(
            "full_name",
            metavar="<full name>",
            nargs="?",
            default=SUPPRESS,
            help="full name of new user",
        )
        parser.add_argument(
            "--password",
            help="password of <PASSWORD>. For development only."
            "Note that we recommend against setting "
            "passwords this way, since they can be snooped by any user account "
            "on the server via `ps -ef` or by any superuser with"
            "read access to the user's bash history.",
        )
        parser.add_argument(
            "--password-file", help="The file containing the password of the new user."
        )
        parser.add_argument(
            "--this-user-has-accepted-the-tos",
            dest="tos",
            action="store_true",
            help="Acknowledgement that the user has already accepted the ToS.",
        )<commit_msg>management: Improve help text for create_user.<commit_after># Library code for use in management commands
from argparse import SUPPRESS, ArgumentParser, RawTextHelpFormatter
from typing import Any, Dict, List, Optional

from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned
from django.core.management.base import BaseCommand, CommandError, CommandParser

from zerver.models import Client, Realm, UserProfile, get_client


def is_integer_string(val: str) -> bool:
    try:
        int(val)
        return True
    except ValueError:
        return False


def check_config() -> None:
    for (setting_name, default) in settings.REQUIRED_SETTINGS:
        # if required setting is the same as default OR is not found in settings,
        # throw error to add/set that setting in config
        try:
            if settings.__getattr__(setting_name) != default:
                continue
        except AttributeError:
            pass

        raise CommandError(f"Error: You must set {setting_name} in /etc/zulip/settings.py.")


class ZulipBaseCommand(BaseCommand):

    # Fix support for multi-line usage
    def create_parser(self, prog_name: str, subcommand: str, **kwargs: Any) -> CommandParser:
        parser = super().create_parser(prog_name, subcommand, **kwargs)
        parser.formatter_class = RawTextHelpFormatter
        return parser

    def add_realm_args(
        self, parser: ArgumentParser, *, required: bool = False, help: Optional[str] = None
    ) -> None:
        if help is None:
            help = """The numeric or string ID (subdomain) of the Zulip organization to modify.
You can use the command list_realms to find ID of the realms in this server."""

        parser.add_argument("-r", "--realm", dest="realm_id", required=required, help=help)

    def add_create_user_args(self, parser: ArgumentParser) -> None:
        parser.add_argument(
            "email",
            metavar="<email>",
            nargs="?",
            default=SUPPRESS,
            help="Email address for the new user",
        )
        parser.add_argument(
            "full_name",
            metavar="<full name>",
            nargs="?",
            default=SUPPRESS,
            help="Full name for the new user",
        )
        parser.add_argument(
            "--password",
            help="""\
<PASSWORD>. Recommended only in a development environment.

Sending passwords via command-line arguments is insecure,
since it can be snooped by any process running on the
server via `ps -ef` or reading bash history. Prefer
--password-file.""",
        )
        parser.add_argument("--password-file", help="File containing a password for the <PASSWORD>.")
        parser.add_argument(
            "--this-user-has-accepted-the-tos",
            dest="tos",
            action="store_true",
            help="Acknowledgement that the user has already accepted the ToS.",
        )
{'fraction_non_alphanumeric': 0.09067796610169492, 'fraction_numerical': 0.0, 'mean_word_length': 2.4711764705882353, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '483028', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1548, 'n_words': 532}