slack: fix type annonations.
This commit is contained in:
parent
1f17c04115
commit
e5726fdc96
|
@ -8,11 +8,11 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List, Tuple
|
||||||
# stubs
|
# stubs
|
||||||
user_profile_stub = Dict[str, Any]
|
ZerverFieldsT = Dict[str, Any]
|
||||||
added_users_stub = Dict[str, int]
|
AddedUsersT = Dict[str, int]
|
||||||
|
AddedChannelsT = Dict[str, int]
|
||||||
|
|
||||||
# Transported from https://github.com/zulip/zulip/blob/master/zerver/lib/export.py
|
# Transported from https://github.com/zulip/zulip/blob/master/zerver/lib/export.py
|
||||||
def rm_tree(path: str) -> None:
|
def rm_tree(path: str) -> None:
|
||||||
|
@ -20,7 +20,7 @@ def rm_tree(path: str) -> None:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def users2zerver_userprofile(slack_dir: str, realm_id: int, timestamp: Any,
|
def users2zerver_userprofile(slack_dir: str, realm_id: int, timestamp: Any,
|
||||||
domain_name: str) -> (List[user_profile_stub], added_users_stub):
|
domain_name: str) -> Tuple[List[ZerverFieldsT], AddedUsersT]:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
1. zerver_userprofile, which is a list of user profile
|
1. zerver_userprofile, which is a list of user profile
|
||||||
|
@ -39,7 +39,7 @@ def users2zerver_userprofile(slack_dir: str, realm_id: int, timestamp: Any,
|
||||||
|
|
||||||
# email
|
# email
|
||||||
if 'email' not in profile:
|
if 'email' not in profile:
|
||||||
email = (hashlib.blake2b(user['real_name'].encode()).hexdigest() +
|
email = (hashlib.sha256(user['real_name'].encode()).hexdigest() +
|
||||||
"@%s" % (domain_name))
|
"@%s" % (domain_name))
|
||||||
else:
|
else:
|
||||||
email = profile['email']
|
email = profile['email']
|
||||||
|
@ -131,8 +131,12 @@ def users2zerver_userprofile(slack_dir: str, realm_id: int, timestamp: Any,
|
||||||
print('######### IMPORTING USERS FINISHED #########\n')
|
print('######### IMPORTING USERS FINISHED #########\n')
|
||||||
return zerver_userprofile, added_users
|
return zerver_userprofile, added_users
|
||||||
|
|
||||||
def channels2zerver_stream(slack_dir, realm_id, added_users, zerver_userprofile):
|
def channels2zerver_stream(slack_dir: str, realm_id: int, added_users: AddedUsersT,
|
||||||
# type: (Dict[str, Dict[str, Any]]) -> None
|
zerver_userprofile: List[ZerverFieldsT]) -> Tuple[List[ZerverFieldsT],
|
||||||
|
List[ZerverFieldsT],
|
||||||
|
AddedChannelsT,
|
||||||
|
List[ZerverFieldsT],
|
||||||
|
List[ZerverFieldsT]]:
|
||||||
print('######### IMPORTING CHANNELS STARTED #########\n')
|
print('######### IMPORTING CHANNELS STARTED #########\n')
|
||||||
channels = json.load(open(slack_dir + '/channels.json'))
|
channels = json.load(open(slack_dir + '/channels.json'))
|
||||||
added_channels = {}
|
added_channels = {}
|
||||||
|
@ -323,11 +327,9 @@ def main(slack_zip_file: str) -> None:
|
||||||
|
|
||||||
# now for message.json
|
# now for message.json
|
||||||
message_json = {}
|
message_json = {}
|
||||||
zerver_message = []
|
zerver_message = [] # type: List[ZerverFieldsT]
|
||||||
zerver_usermessage = []
|
zerver_usermessage = [] # type: List[ZerverFieldsT]
|
||||||
zerver_attachment = []
|
zerver_attachment = [] # type: List[ZerverFieldsT]
|
||||||
zerver_message = []
|
|
||||||
zerver_usermessage = []
|
|
||||||
|
|
||||||
message_json['zerver_message'] = zerver_message
|
message_json['zerver_message'] = zerver_message
|
||||||
message_json['zerver_usermessage'] = zerver_usermessage
|
message_json['zerver_usermessage'] = zerver_usermessage
|
||||||
|
@ -347,8 +349,7 @@ def main(slack_zip_file: str) -> None:
|
||||||
|
|
||||||
# IO attachments
|
# IO attachments
|
||||||
attachment_file = output_dir + '/attachment.json'
|
attachment_file = output_dir + '/attachment.json'
|
||||||
# attachment = {"zerver_attachment": zerver_attachment}
|
attachment = {"zerver_attachment": zerver_attachment}
|
||||||
attachment = {"zerver_attachment": []}
|
|
||||||
json.dump(attachment, open(attachment_file, 'w'))
|
json.dump(attachment, open(attachment_file, 'w'))
|
||||||
|
|
||||||
print('ls', os.listdir())
|
print('ls', os.listdir())
|
||||||
|
|
Loading…
Reference in a new issue