slack importer: Fix output_dir path and remove sys.exit(0).

Also, as the exception is being handled in 'slack_data_to_zulip_data'
remove it from the manage.py command 'convert_slack_data'.
This commit is contained in:
Rhea Parekh
2018-02-09 02:08:14 +05:30
committed by Tim Abbott
parent 699021e7d8
commit a0b7976f77
2 changed files with 6 additions and 4 deletions

View File

@@ -600,6 +600,12 @@ def do_convert_data(slack_zip_file: str, realm_subdomain: str, output_dir: str,
slack_data_dir = slack_zip_file.replace('.zip', '')
if not os.path.exists(slack_data_dir):
os.makedirs(slack_data_dir)
os.makedirs(output_dir, exist_ok=True)
# output directory should be empty initially
if os.listdir(output_dir):
raise Exception('Output directory should be empty!')
subprocess.check_call(['unzip', '-q', slack_zip_file, '-d', slack_data_dir])
# with zipfile.ZipFile(slack_zip_file, 'r') as zip_ref:
# zip_ref.extractall(slack_data_dir)
@@ -639,7 +645,6 @@ def do_convert_data(slack_zip_file: str, realm_subdomain: str, output_dir: str,
logging.info('######### DATA CONVERSION FINISHED #########\n')
logging.info("Zulip data dump created at %s" % (output_dir))
sys.exit(0)
def get_data_file(path: str) -> Any:
data = json.load(open(path))

View File

@@ -35,9 +35,6 @@ class Command(BaseCommand):
output_dir = tempfile.mkdtemp(prefix="/tmp/converted-slack-data-")
else:
output_dir = os.path.realpath(output_dir)
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)
realm_name = options['realm_name']
token = options['token']