Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
import argparse
|
|
import os
|
|
from typing import Any
|
|
|
|
from typing_extensions import override
|
|
|
|
"""
|
|
Example usage for testing purposes. For testing data see the mattermost_fixtures
|
|
in zerver/tests/.
|
|
|
|
./manage.py convert_mattermost_data mattermost_fixtures --output mm_export
|
|
./manage.py import --destroy-rebuild-database mattermost mm_export/gryffindor
|
|
|
|
Test out the realm:
|
|
./tools/run-dev
|
|
go to browser and use your dev url
|
|
"""
|
|
|
|
from django.core.management.base import CommandError, CommandParser
|
|
|
|
from zerver.data_import.mattermost import do_convert_data
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
|
|
|
|
class Command(ZulipBaseCommand):
|
|
help = """Convert the mattermost data into Zulip data format."""
|
|
|
|
@override
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
|
dir_help = (
|
|
"Directory containing exported JSON file and exported_emoji (optional) directory."
|
|
)
|
|
parser.add_argument(
|
|
"mattermost_data_dir", metavar="<mattermost data directory>", help=dir_help
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--output", dest="output_dir", help="Directory to write converted data to."
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--mask",
|
|
dest="masking_content",
|
|
action="store_true",
|
|
help="Mask the content for privacy during QA.",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--combine-teams-into-one-org",
|
|
dest="combine_into_one_realm",
|
|
action="store_true",
|
|
help="Combine all exported teams into one Zulip organization.",
|
|
)
|
|
|
|
parser.formatter_class = argparse.RawTextHelpFormatter
|
|
|
|
@override
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
|
output_dir = options["output_dir"]
|
|
if output_dir is None:
|
|
raise CommandError("You need to specify --output <output directory>")
|
|
|
|
if os.path.exists(output_dir) and not os.path.isdir(output_dir):
|
|
raise CommandError(output_dir + " is not a directory")
|
|
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
if os.listdir(output_dir):
|
|
raise CommandError("Output directory should be empty!")
|
|
output_dir = os.path.realpath(output_dir)
|
|
|
|
data_dir = options["mattermost_data_dir"]
|
|
if not os.path.exists(data_dir):
|
|
raise CommandError(f"Directory not found: '{data_dir}'")
|
|
data_dir = os.path.realpath(data_dir)
|
|
|
|
print("Converting data ...")
|
|
do_convert_data(
|
|
mattermost_data_dir=data_dir,
|
|
output_dir=output_dir,
|
|
masking_content=options.get("masking_content", False),
|
|
combine_into_one_realm=options.get("combine_into_one_realm", False),
|
|
)
|