snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
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
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
This commit is contained in:
87
zerver/management/commands/convert_slack_data.py
Normal file
87
zerver/management/commands/convert_slack_data.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import argparse
|
||||
import os
|
||||
import tempfile
|
||||
from typing import Any
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import CommandError, CommandParser
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.data_import.slack import do_convert_directory, do_convert_zipfile
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """Convert the Slack data into Zulip data format."""
|
||||
|
||||
@override
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
parser.add_argument(
|
||||
"slack_data_path",
|
||||
nargs="+",
|
||||
metavar="<Slack data path>",
|
||||
help="Zipped Slack data or directory",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--token", metavar="<slack_token>", help="Bot user OAuth token, starting xoxb-"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--output", dest="output_dir", help="Directory to write exported data to."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--processes",
|
||||
default=settings.DEFAULT_DATA_EXPORT_IMPORT_PARALLELISM,
|
||||
help="Processes to use in exporting UserMessage objects in parallel",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--no-convert-slack-threads",
|
||||
action="store_true",
|
||||
help="If specified, do not convert Slack threads to separate Zulip topics",
|
||||
)
|
||||
|
||||
parser.formatter_class = argparse.RawTextHelpFormatter
|
||||
|
||||
@override
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
output_dir = options["output_dir"]
|
||||
if output_dir is None:
|
||||
output_dir = tempfile.mkdtemp(prefix="converted-slack-data-")
|
||||
else:
|
||||
output_dir = os.path.realpath(output_dir)
|
||||
|
||||
token = options["token"]
|
||||
if token is None:
|
||||
raise CommandError("Enter Slack legacy token!")
|
||||
|
||||
num_processes = int(options["processes"])
|
||||
if num_processes < 1:
|
||||
raise CommandError("You must have at least one process.")
|
||||
|
||||
for path in options["slack_data_path"]:
|
||||
if not os.path.exists(path):
|
||||
raise CommandError(f"Slack data file or directory not found: '{path}'")
|
||||
|
||||
print("Converting data ...")
|
||||
convert_slack_threads = not options["no_convert_slack_threads"]
|
||||
if os.path.isdir(path):
|
||||
do_convert_directory(
|
||||
path,
|
||||
output_dir,
|
||||
token,
|
||||
processes=num_processes,
|
||||
convert_slack_threads=convert_slack_threads,
|
||||
)
|
||||
elif os.path.isfile(path) and path.endswith(".zip"):
|
||||
do_convert_zipfile(
|
||||
path,
|
||||
output_dir,
|
||||
token,
|
||||
processes=num_processes,
|
||||
convert_slack_threads=convert_slack_threads,
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Don't know how to import Slack data from {path}")
|
||||
Reference in New Issue
Block a user