import: De-dup create_converted_data_files helper.

This commit is contained in:
Steve Howell 2018-10-13 14:41:18 +00:00 committed by Tim Abbott
parent 91905bd66a
commit 23d7b3d2cc
4 changed files with 9 additions and 17 deletions

View File

@ -18,7 +18,7 @@ from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
from zerver.data_import.import_util import ZerverFieldsT, build_zerver_realm, \
build_avatar, build_subscription, build_recipient, build_usermessages, \
build_defaultstream, process_avatars, build_realm, build_stream, \
build_message
build_message, create_converted_data_files
# stubs
GitterDataT = List[Dict[str, Any]]
@ -268,11 +268,6 @@ def do_convert_data(gitter_data_file: str, output_dir: str, threads: int=6) -> N
logging.info('######### DATA CONVERSION FINISHED #########\n')
logging.info("Zulip data dump created at %s" % (output_dir))
def create_converted_data_files(data: Any, output_dir: str, file_path: str) -> None:
output_file = output_dir + file_path
os.makedirs(os.path.dirname(output_file), exist_ok=True)
json.dump(data, open(output_file, 'w'), indent=4)
def write_data_to_file(output_file: str, data: Any) -> None:
with open(output_file, "w") as f:
f.write(ujson.dumps(data, indent=4))

View File

@ -29,6 +29,7 @@ from zerver.data_import.import_util import (
build_user,
build_user_message,
build_zerver_realm,
create_converted_data_files,
write_avatar_png,
)
@ -538,9 +539,3 @@ def do_convert_data(input_tar_file: str, output_dir: str) -> None:
)
subprocess.check_call(["tar", "-czf", output_dir + '.tar.gz', output_dir, '-P'])
# TODO: everything below is verbatim from slack.py
def create_converted_data_files(data: Any, output_dir: str, file_path: str) -> None:
output_file = output_dir + file_path
json.dump(data, open(output_file, 'w'), indent=4)

View File

@ -1,3 +1,4 @@
import json
import random
import requests
import shutil
@ -504,3 +505,8 @@ def process_emojis(zerver_realmemoji: List[ZerverFieldsT], emoji_dir: str,
logging.info('######### GETTING EMOJIS FINISHED #########\n')
return emoji_records
def create_converted_data_files(data: Any, output_dir: str, file_path: str) -> None:
output_file = output_dir + file_path
os.makedirs(os.path.dirname(output_file), exist_ok=True)
json.dump(data, open(output_file, 'w'), indent=4)

View File

@ -24,7 +24,7 @@ from zerver.data_import.slack_message_conversion import convert_to_zulip_markdow
from zerver.data_import.import_util import ZerverFieldsT, build_zerver_realm, \
build_avatar, build_subscription, build_recipient, build_usermessages, \
build_defaultstream, build_attachment, process_avatars, process_uploads, \
process_emojis, build_realm, build_stream, build_message
process_emojis, build_realm, build_stream, build_message, create_converted_data_files
from zerver.lib.parallel import run_parallel
from zerver.lib.upload import random_name, sanitize_name
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
@ -805,7 +805,3 @@ def get_slack_api_data(token: str, slack_api_url: str, get_param: str) -> Any:
return json_data
else:
raise Exception('Something went wrong. Please try again!')
def create_converted_data_files(data: Any, output_dir: str, file_path: str) -> None:
output_file = output_dir + file_path
json.dump(data, open(output_file, 'w'), indent=4)