From 6fdd42c08b856edb0b863afe17d9e356a679fb14 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 11 Aug 2016 14:59:19 -0700 Subject: [PATCH] export: Create convenient soft links. --- zerver/lib/export.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zerver/lib/export.py b/zerver/lib/export.py index 226943cbc5..e3304d7013 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -855,9 +855,10 @@ def do_export_realm(realm, output_dir, threads): # enforce this for us. assert threads >= 1 - realm_config = get_realm_config() + create_soft_link(source=output_dir, in_progress=True) + logging.info("Exporting realm configuration") export_from_config( response=response, @@ -896,6 +897,23 @@ def do_export_realm(realm, output_dir, threads): launch_user_message_subprocesses(threads=threads, output_dir=output_dir) logging.info("Finished exporting %s" % (realm.domain)) + create_soft_link(source=output_dir, in_progress=False) + +def create_soft_link(source, in_progress=True): + is_done = not in_progress + in_progress_link = '/tmp/zulip-export-in-progress' + done_link = '/tmp/zulip-export-most-recent' + + if in_progress: + new_target = in_progress_link + else: + subprocess.check_call(['rm', '-f', in_progress_link]) + new_target = done_link + + subprocess.check_call(["ln", "-nsf", source, new_target]) + if is_done: + logging.info('See %s for output files' % (new_target,)) + def launch_user_message_subprocesses(threads, output_dir): # type: (int, Path) -> None