Files
zulip/tools/purge-deployments
Tim Abbott 130d381302 Rename humbug_tools to zulip_tools.
(imported from commit 7f21fdc2c2d6ad0bdbd99eb616ffc75c347d8dcb)
2013-08-07 10:00:08 -04:00

29 lines
898 B
Python
Executable File

#!/usr/bin/python
import os
import logging
import datetime
import shutil
from zulip_tools import DEPLOYMENTS_DIR, TIMESTAMP_FORMAT
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:
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")