def get_caches_in_use(threshold_days): # type: (int) -> Set[str] setups_to_check = set([ZULIP_PATH, ]) caches_in_use = set() def add_current_venv_cache(venv_name: str) -> None: CACHE_SYMLINK = os.path.join(os.path.dirname(ZULIP_PATH), venv_name) CURRENT_CACHE = os.path.dirname(os.path.realpath(CACHE_SYMLINK)) caches_in_use.add(CURRENT_CACHE) if ENV == "prod": setups_to_check |= get_recent_deployments(threshold_days) if ENV == "dev": add_current_venv_cache("zulip-py3-venv") add_current_venv_cache("zulip-thumbor-venv") for path in setups_to_check: reqs_dir = os.path.join(path, "requirements") # If the target directory doesn't contain a requirements # directory, skip it to avoid throwing an exception trying to # list its requirements subdirectory. if not os.path.exists(reqs_dir): continue for filename in os.listdir(reqs_dir): requirements_file = os.path.join(reqs_dir, filename) deps = expand_reqs(requirements_file) hash_val = hash_deps(deps) caches_in_use.add(os.path.join(VENV_CACHE_DIR, hash_val)) return caches_in_use
def get_caches_in_use(threshold_days): # type: (int) -> Set[str] setups_to_check = set([ ZULIP_PATH, ]) caches_in_use = set() if ENV == "prod": setups_to_check |= get_recent_deployments(threshold_days) if ENV == "dev": # In dev always include the currently active cache in order # not to break current installation in case dependencies # are updated with bumping the provision version. CURRENT_CACHE = os.path.dirname( os.path.realpath(os.path.join(ZULIP_PATH, "node_modules"))) caches_in_use.add(CURRENT_CACHE) for setup_dir in setups_to_check: node_modules_link_path = os.path.join(setup_dir, "node_modules") if not os.path.islink(node_modules_link_path): # If 'package.json' file doesn't exist then no node_modules # cache is associated with this setup. continue # The actual cache path doesn't include the /node_modules caches_in_use.add(os.path.dirname(os.readlink(node_modules_link_path))) return caches_in_use
def get_caches_in_use(threshold_days): # type: (int) -> Set[str] setups_to_check = set([ZULIP_PATH, ]) caches_in_use = set() if ENV == "prod": setups_to_check |= get_recent_deployments(threshold_days) if ENV == "dev": CACHE_SYMLINK = os.path.join(ZULIP_PATH, "static", "generated", "emoji") CURRENT_CACHE = os.path.dirname(os.path.realpath(CACHE_SYMLINK)) caches_in_use.add(CURRENT_CACHE) for setup_dir in setups_to_check: emoji_link_path = os.path.join(setup_dir, "static/generated/emoji") if not os.path.islink(emoji_link_path): # This happens for a deployment directory extracted from a # tarball, which just has a copy of the emoji data, not a symlink. continue caches_in_use.add(os.readlink(emoji_link_path)) return caches_in_use
def get_caches_in_use(threshold_days): # type: (int) -> Set[str] setups_to_check = set([ZULIP_PATH, ]) caches_in_use = set() if ENV == "prod": setups_to_check |= get_recent_deployments(threshold_days) if ENV == "dev": # In dev always include the currently active cache in order # not to break current installation in case dependencies # are updated with bumping the provision version. CURRENT_CACHE = os.path.dirname(os.path.realpath(os.path.join(ZULIP_PATH, "node_modules"))) caches_in_use.add(CURRENT_CACHE) for setup_dir in setups_to_check: node_modules_link_path = os.path.join(setup_dir, "node_modules") if not os.path.islink(node_modules_link_path): # If 'package.json' file doesn't exist then no node_modules # cache is associated with this setup. continue caches_in_use.add(os.readlink(node_modules_link_path)) return caches_in_use