zulip/tools/clean-emoji-cache

24 lines
916 B
Python
Executable File

#!/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,))