2016-04-07 15:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
2013-10-25 23:20:40 +02:00
|
|
|
import sys
|
2013-05-16 18:03:01 +02:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import datetime
|
|
|
|
import shutil
|
2013-10-25 23:20:40 +02:00
|
|
|
|
2013-10-25 23:46:02 +02:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
2013-08-06 22:39:20 +02:00
|
|
|
from zulip_tools import DEPLOYMENTS_DIR, TIMESTAMP_FORMAT
|
2013-05-16 18:03:01 +02:00
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s purge-deployments: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
|
|
|
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
|
|
|
|
to_purge = []
|
|
|
|
for filename in os.listdir(DEPLOYMENTS_DIR):
|
|
|
|
try:
|
|
|
|
date = datetime.datetime.strptime(filename, TIMESTAMP_FORMAT)
|
|
|
|
if date < one_week_ago:
|
2013-10-31 18:22:23 +01:00
|
|
|
if (os.path.abspath(os.readlink("/home/zulip/deployments/current")) ==
|
|
|
|
os.path.abspath(os.path.join(DEPLOYMENTS_DIR, filename))):
|
|
|
|
# Never purge the currently running deployment
|
|
|
|
continue
|
2013-05-16 18:03:01 +02:00
|
|
|
to_purge.append(filename)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if to_purge:
|
|
|
|
to_purge.sort()
|
|
|
|
logging.info("Purging the following old deployments directories: %s" % (", ".join(to_purge),))
|
|
|
|
for filename in to_purge:
|
|
|
|
shutil.rmtree(os.path.join(DEPLOYMENTS_DIR, filename))
|
|
|
|
logging.info("Finished %s" % (filename))
|
|
|
|
else:
|
|
|
|
logging.info("No old deployment directories to purge")
|