2013-08-21 23:22:10 +02:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2013-08-21 23:22:10 +02:00
|
|
|
|
|
|
|
from zerver.lib.actions import do_rename_stream
|
2016-07-05 04:20:18 +02:00
|
|
|
from zerver.lib.str_utils import force_text
|
2017-08-07 22:14:42 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
|
|
from zerver.models import get_stream
|
2013-08-21 23:22:10 +02:00
|
|
|
|
2013-08-22 23:29:29 +02:00
|
|
|
import sys
|
|
|
|
|
2017-08-07 22:14:42 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2015-08-21 02:10:41 +02:00
|
|
|
help = """Change the stream name for a realm."""
|
2013-08-21 23:22:10 +02:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('old_name', metavar='<old name>', type=str,
|
|
|
|
help='name of stream to be renamed')
|
|
|
|
parser.add_argument('new_name', metavar='<new name>', type=str,
|
|
|
|
help='new name to rename the stream to')
|
2017-08-07 22:14:42 +02:00
|
|
|
self.add_realm_args(parser, True)
|
2013-08-21 23:22:10 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2017-08-07 22:14:42 +02:00
|
|
|
realm = self.get_realm(options)
|
2017-09-26 01:25:39 +02:00
|
|
|
assert realm is not None # Should be ensured by parser
|
2015-08-21 02:10:41 +02:00
|
|
|
old_name = options['old_name']
|
|
|
|
new_name = options['new_name']
|
2013-08-22 23:29:29 +02:00
|
|
|
encoding = sys.getfilesystemencoding()
|
2013-08-21 23:22:10 +02:00
|
|
|
|
2017-01-30 04:05:39 +01:00
|
|
|
stream = get_stream(force_text(old_name, encoding), realm)
|
|
|
|
do_rename_stream(stream, force_text(new_name, encoding))
|