From 71e02d7893367a3195c4180215da8dabb5c32888 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 3 Feb 2022 01:27:45 +0000 Subject: [PATCH] zulip_tools: Factor out ZULIP_VERSION parsing. --- scripts/lib/zulip_tools.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index 2481cd77a4..0b8e1eabc0 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -105,15 +105,20 @@ def get_deploy_root() -> str: ) +def parse_version_from(deploy_path: str) -> str: + with open(os.path.join(deploy_path, "version.py")) as f: + result = re.search('ZULIP_VERSION = "(.*)"', f.read()) + if result: + return result.groups()[0] + return "0.0.0" + + def get_deployment_version(extract_path: str) -> str: version = "0.0.0" for item in os.listdir(extract_path): item_path = os.path.join(extract_path, item) if item.startswith("zulip-server") and os.path.isdir(item_path): - with open(os.path.join(item_path, "version.py")) as f: - result = re.search('ZULIP_VERSION = "(.*)"', f.read()) - if result: - version = result.groups()[0] + version = parse_version_from(item_path) break return version