diff --git a/tools/clean-emoji-cache b/tools/clean-emoji-cache new file mode 100755 index 0000000000..be473cc3ea --- /dev/null +++ b/tools/clean-emoji-cache @@ -0,0 +1,23 @@ +#!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function +import os +import subprocess +import sys + +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +EMOJI_CACHE_SYMLINK = os.path.join(ZULIP_PATH, 'static', 'generated', 'emoji') +EMOJI_CACHE_PATH = "/srv/zulip-emoji-cache" +if "--travis" in sys.argv: + EMOJI_CACHE_PATH = os.path.join(os.environ["HOME"], "zulip-emoji-cache") + +curr_emoji_cache_dir = os.path.dirname(os.path.realpath(EMOJI_CACHE_SYMLINK)) + +for cache_dir_base in os.listdir(EMOJI_CACHE_PATH): + emoji_cache_dir = os.path.join(EMOJI_CACHE_PATH, cache_dir_base) + if emoji_cache_dir not in curr_emoji_cache_dir: + print("Cleaning unused emoji cache dir %s" % (emoji_cache_dir,)) + subprocess.check_call(["sudo", "rm", "-rf", emoji_cache_dir]) + else: + print("Keeping used emoji cache dir %s" % (emoji_cache_dir,))