From 031dfbcc46019a0a82e7c4fc8b2db9946d7d58dc Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Wed, 13 Nov 2013 14:57:31 -0500 Subject: [PATCH] zulip_tools.py: Add a make_deploy_path function and make it invokable from the commandline (imported from commit 94578d117864fba76f9353784734c712c89c4bf2) --- scripts/unpack-zulip | 5 ++--- tools/update-deployment | 5 ++--- zulip_tools.py | 13 ++++++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/unpack-zulip b/scripts/unpack-zulip index bf10517140..a19c1b32ac 100755 --- a/scripts/unpack-zulip +++ b/scripts/unpack-zulip @@ -6,7 +6,7 @@ import datetime import tempfile sys.path.append(os.path.join(os.path.dirname(__file__), '..')) -from zulip_tools import DEPLOYMENTS_DIR, TIMESTAMP_FORMAT, FAIL, ENDC +from zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, make_deploy_path if len(sys.argv) != 2: print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC @@ -14,8 +14,7 @@ if len(sys.argv) != 2: tarball_path = sys.argv[1] -timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) -deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp) +deploy_path = make_deploy_path() extract_path = tempfile.mkdtemp() subprocess.check_call(["tar", "-xf", tarball_path, "-C", extract_path]) diff --git a/tools/update-deployment b/tools/update-deployment index 52fa7d5818..904d47123a 100755 --- a/tools/update-deployment +++ b/tools/update-deployment @@ -8,7 +8,7 @@ import shutil import time sys.path.append(os.path.join(os.path.dirname(__file__), '..')) -from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, WARNING, ENDC +from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, make_deploy_path logging.basicConfig(format="%(asctime)s update-deployment: %(message)s", level=logging.INFO) @@ -40,8 +40,7 @@ if not got_lock: + "manually when the current deployment finishes." + ENDC sys.exit(1) -timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) -deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp) +deploy_path = make_deploy_path() logging.info("Cloning the repository") subprocess.check_call(["git", "clone", "-q", "-b", refname, diff --git a/zulip_tools.py b/zulip_tools.py index b021803103..08650c72ac 100755 --- a/zulip_tools.py +++ b/zulip_tools.py @@ -1,5 +1,7 @@ -import subprocess +#!/usr/bin/python import os +import sys +import datetime DEPLOYMENTS_DIR = "/home/zulip/deployments" LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock") @@ -11,3 +13,12 @@ OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' + +def make_deploy_path(): + timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) + return os.path.join(DEPLOYMENTS_DIR, timestamp) + +if __name__ == '__main__': + cmd = sys.argv[1] + if cmd == 'make_deploy_path': + print make_deploy_path()