<commit_before>from __future__ import absolute_import
from __future__ import print_function

from typing import Any

from argparse import ArgumentParser
from django.core.management.base import BaseCommand
from zerver.lib.actions import do_change_user_email
from zerver.models import UserProfile, get_user_profile_by_email

class Command(BaseCommand):
    help = """Change the email address for a user."""

    def add_arguments(self, parser):
        # type: (ArgumentParser) -> None
        parser.add_argument('old_email', metavar='<old email>', type=str,
                            help='email address to change')
        parser.add_argument('new_email', metavar='<new email>', type=str,
                            help='new email address')

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        old_email = options['old_email']
        new_email = options['new_email']
        try:
            user_profile = get_user_profile_by_email(old_email)
        except UserProfile.DoesNotExist:
            print("Old e-mail doesn't exist in the system.")
            exit(1)

        do_change_user_email(user_profile, new_email)<commit_msg>change_user_email: Use new get_user_for_mgmt function.<commit_after>from __future__ import absolute_import
from __future__ import print_function

import sys

from argparse import ArgumentParser
from django.core.management.base import BaseCommand
from typing import Any

from zerver.lib.actions import do_change_user_email
from zerver.models import UserProfile, get_user_for_mgmt

class Command(BaseCommand):
    help = """Change the email address for a user."""

    def add_arguments(self, parser):
        # type: (ArgumentParser) -> None
        parser.add_argument('old_email', metavar='<old email>', type=str,
                            help='email address to change')
        parser.add_argument('new_email', metavar='<new email>', type=str,
                            help='new email address')

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        old_email = options['old_email']
        new_email = options['new_email']
        try:
            user_profile = get_user_for_mgmt(old_email)
        except UserProfile.DoesNotExist:
            print("Old e-mail doesn't exist in the system.")
            sys.exit(1)

        do_change_user_email(user_profile, new_email)
{'fraction_non_alphanumeric': 0.09433962264150944, 'fraction_numerical': 0.0008385744234800838, 'mean_word_length': 3.0440677966101695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '5621278', 'n_tokens_mistral': 673, 'n_tokens_neox': 663, 'n_words': 179}