py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
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__), '..'))
|
2016-08-13 17:46:19 +02:00
|
|
|
from scripts.lib.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)
|
|
|
|
|
2016-08-05 01:59:13 +02:00
|
|
|
deployments_in_use = set()
|
|
|
|
for basename in ['current', 'last', 'next']:
|
|
|
|
# Note which symlinks are current
|
|
|
|
path = os.path.abspath(os.readlink(os.path.join(DEPLOYMENTS_DIR, basename)))
|
|
|
|
deployments_in_use.add(path)
|
|
|
|
|
2013-05-16 18:03:01 +02:00
|
|
|
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:
|
2016-08-05 01:59:13 +02:00
|
|
|
if os.path.abspath(os.path.join(DEPLOYMENTS_DIR, filename)) in deployments_in_use:
|
|
|
|
# Never purge an in-use deployment
|
2013-10-31 18:22:23 +01:00
|
|
|
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")
|