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
|
2012-08-28 18:45:35 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2018-08-08 21:28:43 +02:00
|
|
|
import types
|
2012-08-28 18:45:35 +02:00
|
|
|
|
2016-06-25 17:07:13 +02:00
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
sys.path.append(BASE_DIR)
|
|
|
|
import scripts.lib.setup_path_on_import
|
|
|
|
|
2012-08-28 18:45:35 +02:00
|
|
|
if __name__ == "__main__":
|
2018-07-30 21:09:24 +02:00
|
|
|
if 'posix' in os.name and os.geteuid() == 0:
|
|
|
|
print("manage.py should not be run as root. Use `su zulip` to drop root.")
|
|
|
|
sys.exit(1)
|
|
|
|
if (os.access('/etc/zulip/zulip.conf', os.R_OK) and not
|
|
|
|
os.access('/etc/zulip/zulip-secrets.conf', os.R_OK)):
|
|
|
|
# The best way to detect running manage.py as another user in
|
|
|
|
# production before importing anything that would require that
|
|
|
|
# access is to check for access to /etc/zulip/zulip.conf (in
|
|
|
|
# which case it's a production server, not a dev environment)
|
|
|
|
# and lack of access for /etc/zulip/zulip-secrets.conf (which
|
|
|
|
# should be only readable by root and zulip)
|
|
|
|
print("Error accessing Zulip secrets; manage.py in production must be run as the zulip user.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-08 21:28:43 +02:00
|
|
|
# Performance Hack: We make the pika.adapters.twisted_connection
|
|
|
|
# module unavailable, to save ~100ms of import time for most Zulip
|
|
|
|
# management commands for code we don't use. The correct
|
|
|
|
# long-term fix for this will be to get a setting integrated
|
|
|
|
# upstream to disable pika importing this.
|
|
|
|
# See https://github.com/pika/pika/issues/1128
|
|
|
|
sys.modules['pika.adapters.twisted_connection'] = types.ModuleType(
|
|
|
|
'pika.adapters.twisted_connection')
|
|
|
|
|
2013-11-19 00:04:45 +01:00
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings")
|
|
|
|
from django.conf import settings
|
2017-08-18 22:23:46 +02:00
|
|
|
from django.core.management import execute_from_command_line
|
2017-07-07 20:50:50 +02:00
|
|
|
from django.core.management.base import CommandError
|
2017-08-18 06:36:37 +02:00
|
|
|
from scripts.lib.zulip_tools import log_management_command
|
2013-11-19 00:04:45 +01:00
|
|
|
|
2017-08-18 06:36:37 +02:00
|
|
|
log_management_command(" ".join(sys.argv), settings.MANAGEMENT_LOG_PATH)
|
2013-05-22 21:18:45 +02:00
|
|
|
|
2017-08-18 22:23:46 +02:00
|
|
|
os.environ.setdefault("PYTHONSTARTUP", os.path.join(BASE_DIR, "scripts/lib/pythonrc.py"))
|
2013-05-22 21:18:45 +02:00
|
|
|
if "--no-traceback" not in sys.argv and len(sys.argv) > 1:
|
|
|
|
sys.argv.append("--traceback")
|
2017-07-07 20:50:50 +02:00
|
|
|
try:
|
|
|
|
execute_from_command_line(sys.argv)
|
|
|
|
except CommandError as e:
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
sys.exit(1)
|