2018-09-28 13:00:32 +02:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
'''
|
|
|
|
Example usage for testing purposes:
|
|
|
|
|
|
|
|
Move the data:
|
2019-01-15 02:56:06 +01:00
|
|
|
rm -Rf ~/hipchat-data
|
|
|
|
mkdir ~/hipchat-data
|
|
|
|
./manage.py convert_hipchat_data ~/hipchat-31028-2018-08-08_23-23-22.tar --output ~/hipchat-data
|
|
|
|
./manage.py import --destroy-rebuild-database hipchat ~/hipchat-data
|
2018-09-28 13:00:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
Test out the realm:
|
|
|
|
./tools/run-dev.py
|
|
|
|
go to browser and use your dev url
|
2018-10-13 01:27:29 +02:00
|
|
|
|
|
|
|
spec:
|
|
|
|
https://confluence.atlassian.com/hipchatkb/
|
|
|
|
exporting-from-hipchat-server-or-data-center-for-data-portability-950821555.html
|
2018-09-28 13:00:32 +02:00
|
|
|
'''
|
|
|
|
|
2019-02-02 23:53:29 +01:00
|
|
|
from django.core.management.base import BaseCommand, CommandParser
|
2018-09-28 13:00:32 +02:00
|
|
|
|
|
|
|
from zerver.data_import.hipchat import do_convert_data
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Convert the Hipchat data into Zulip data format."""
|
|
|
|
|
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
|
|
|
parser.add_argument('hipchat_tar', nargs='+',
|
|
|
|
metavar='<hipchat data tarfile>',
|
|
|
|
help="tar of Hipchat data")
|
|
|
|
|
|
|
|
parser.add_argument('--output', dest='output_dir',
|
|
|
|
action="store",
|
|
|
|
help='Directory to write exported data to.')
|
|
|
|
|
2018-10-25 00:57:11 +02:00
|
|
|
parser.add_argument('--mask', dest='masking_content',
|
|
|
|
action="store_true",
|
|
|
|
help='Mask the content for privacy during QA.')
|
|
|
|
|
2019-01-10 00:42:38 +01:00
|
|
|
parser.add_argument('--slim-mode', dest='slim_mode',
|
|
|
|
action="store_true",
|
2019-02-08 01:17:01 +01:00
|
|
|
help="Default to no public stream subscriptions if no token is available." +
|
|
|
|
" See import docs for details.")
|
2019-01-10 00:42:38 +01:00
|
|
|
|
|
|
|
parser.add_argument('--token', dest='api_token',
|
|
|
|
action="store",
|
|
|
|
help='API token for the HipChat API for fetching subscribers.')
|
|
|
|
|
2018-09-28 13:00:32 +02:00
|
|
|
parser.formatter_class = argparse.RawTextHelpFormatter
|
|
|
|
|
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
|
|
|
output_dir = options["output_dir"]
|
|
|
|
|
|
|
|
if output_dir is None:
|
|
|
|
print("You need to specify --output <output directory>")
|
|
|
|
exit(1)
|
|
|
|
|
2018-11-01 01:09:52 +01:00
|
|
|
if os.path.exists(output_dir) and not os.path.isdir(output_dir):
|
2018-09-28 13:00:32 +02:00
|
|
|
print(output_dir + " is not a directory")
|
|
|
|
exit(1)
|
|
|
|
|
2018-11-01 01:09:52 +01:00
|
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
|
2018-09-28 13:00:32 +02:00
|
|
|
if os.listdir(output_dir):
|
|
|
|
print('Output directory should be empty!')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
output_dir = os.path.realpath(output_dir)
|
|
|
|
|
|
|
|
for path in options['hipchat_tar']:
|
|
|
|
if not os.path.exists(path):
|
|
|
|
print("Tar file not found: '%s'" % (path,))
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
print("Converting Data ...")
|
2018-10-25 00:57:11 +02:00
|
|
|
do_convert_data(
|
|
|
|
input_tar_file=path,
|
|
|
|
output_dir=output_dir,
|
|
|
|
masking_content=options.get('masking_content', False),
|
2019-01-10 00:42:38 +01:00
|
|
|
slim_mode=options['slim_mode'],
|
|
|
|
api_token=options.get("api_token"),
|
2018-10-25 00:57:11 +02:00
|
|
|
)
|