From 70bfcd340265237add37ab15410f8dfa8dad95c3 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 6 Feb 2019 16:32:34 -0800 Subject: [PATCH] zulip_tools: Extract get_deploy_root function. Modified by tabbott from the original to preserve the implementation; see https://github.com/zulip/zulip/pull/11295#discussion_r254925032 for why this is correct. Signed-off-by: Anders Kaseorg --- scripts/lib/zulip_tools.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index b34955f2db..2b8028050c 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -80,6 +80,13 @@ def parse_cache_script_args(description): args.verbose |= args.dry_run # Always print a detailed report in case of dry run. return args +def get_deploy_root() -> str: + # This calls realpath twice to handle both symlinks and users + # running our scripts with relative paths from a current working + # directory of `scripts/`. + return os.path.realpath(os.path.dirname(os.path.dirname( + os.path.dirname(os.path.realpath(__file__))))) + def get_deployment_version(extract_path): # type: (str) -> str version = '0.0.0' @@ -122,8 +129,7 @@ if __name__ == '__main__': def get_dev_uuid_var_path(create_if_missing=False): # type: (bool) -> str - zulip_path = os.path.realpath(os.path.dirname(os.path.dirname( - os.path.dirname(os.path.realpath(__file__))))) + zulip_path = get_deploy_root() uuid_path = os.path.join(os.path.realpath(os.path.dirname(zulip_path)), ".zulip-dev-uuid") if os.path.exists(uuid_path): with open(uuid_path) as f: