2015-10-04 18:56:26 +02:00
|
|
|
#!/usr/bin/env python2.7
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2016-01-10 20:36:38 +01:00
|
|
|
import errno
|
2013-05-16 18:02:25 +02:00
|
|
|
import os
|
2013-11-13 20:57:31 +01:00
|
|
|
import sys
|
|
|
|
import datetime
|
2013-11-13 21:54:30 +01:00
|
|
|
import pwd
|
2013-02-19 02:36:59 +01:00
|
|
|
|
2013-10-04 19:19:57 +02:00
|
|
|
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
2013-05-16 18:02:25 +02:00
|
|
|
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
|
|
|
TIMESTAMP_FORMAT = '%Y-%m-%d-%H-%M-%S'
|
2013-06-05 00:21:47 +02:00
|
|
|
|
|
|
|
# Color codes
|
|
|
|
OKBLUE = '\033[94m'
|
|
|
|
OKGREEN = '\033[92m'
|
|
|
|
WARNING = '\033[93m'
|
|
|
|
FAIL = '\033[91m'
|
|
|
|
ENDC = '\033[0m'
|
2013-11-13 20:57:31 +01:00
|
|
|
|
2013-11-13 21:54:30 +01:00
|
|
|
def su_to_zulip():
|
|
|
|
pwent = pwd.getpwnam("zulip")
|
|
|
|
os.setgid(pwent.pw_gid)
|
|
|
|
os.setuid(pwent.pw_uid)
|
|
|
|
|
2013-11-13 20:57:31 +01:00
|
|
|
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':
|
2015-11-01 17:11:06 +01:00
|
|
|
print(make_deploy_path())
|
2016-01-10 20:36:38 +01:00
|
|
|
|
|
|
|
def mkdir_p(path):
|
|
|
|
# Python doesn't have an analog to `mkdir -p` < Python 3.2.
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno == errno.EEXIST and os.path.isdir(path):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise
|