Annotate zulip_tools.py.

This commit is contained in:
Eklavya Sharma 2016-07-12 20:38:35 +05:30 committed by Tim Abbott
parent 934a0f7c6c
commit 05c9f09850
1 changed files with 10 additions and 0 deletions

View File

@ -9,6 +9,9 @@ import subprocess
import sys import sys
import time import time
if False:
from typing import Sequence
DEPLOYMENTS_DIR = "/home/zulip/deployments" DEPLOYMENTS_DIR = "/home/zulip/deployments"
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock") LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
TIMESTAMP_FORMAT = '%Y-%m-%d-%H-%M-%S' TIMESTAMP_FORMAT = '%Y-%m-%d-%H-%M-%S'
@ -21,14 +24,17 @@ FAIL = '\033[91m'
ENDC = '\033[0m' ENDC = '\033[0m'
def subprocess_text_output(args): def subprocess_text_output(args):
# type: (Sequence[str]) -> str
return subprocess.check_output(args, universal_newlines=True).strip() return subprocess.check_output(args, universal_newlines=True).strip()
def su_to_zulip(): def su_to_zulip():
# type: () -> None
pwent = pwd.getpwnam("zulip") pwent = pwd.getpwnam("zulip")
os.setgid(pwent.pw_gid) os.setgid(pwent.pw_gid)
os.setuid(pwent.pw_uid) os.setuid(pwent.pw_uid)
def make_deploy_path(): def make_deploy_path():
# type: () -> str
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
return os.path.join(DEPLOYMENTS_DIR, timestamp) return os.path.join(DEPLOYMENTS_DIR, timestamp)
@ -38,6 +44,7 @@ if __name__ == '__main__':
print(make_deploy_path()) print(make_deploy_path())
def mkdir_p(path): def mkdir_p(path):
# type: (str) -> None
# Python doesn't have an analog to `mkdir -p` < Python 3.2. # Python doesn't have an analog to `mkdir -p` < Python 3.2.
try: try:
os.makedirs(path) os.makedirs(path)
@ -48,6 +55,7 @@ def mkdir_p(path):
raise raise
def get_deployment_lock(error_rerun_script): def get_deployment_lock(error_rerun_script):
# type: (str) -> None
start_time = time.time() start_time = time.time()
got_lock = False got_lock = False
while time.time() - start_time < 300: while time.time() - start_time < 300:
@ -70,9 +78,11 @@ def get_deployment_lock(error_rerun_script):
sys.exit(1) sys.exit(1)
def release_deployment_lock(): def release_deployment_lock():
# type: () -> None
shutil.rmtree(LOCK_DIR) shutil.rmtree(LOCK_DIR)
def run(args): def run(args):
# type: (Sequence[str]) -> int
# Output what we're doing in the `set -x` style # Output what we're doing in the `set -x` style
print("+ %s" % (" ".join(args))) print("+ %s" % (" ".join(args)))
process = subprocess.Popen(args) process = subprocess.Popen(args)