2009-10-21 03:29:27 +04:00
|
|
|
#!/usr/bin/env python
|
2011-07-29 20:57:58 +04:00
|
|
|
import logging
|
2010-01-29 22:32:20 +03:00
|
|
|
import os
|
2009-10-22 04:31:24 +04:00
|
|
|
import site
|
2010-03-13 02:37:51 +03:00
|
|
|
import sys
|
2012-02-01 04:11:05 +04:00
|
|
|
import warnings
|
2012-07-19 12:50:57 +04:00
|
|
|
|
|
|
|
|
2010-01-29 22:32:20 +03:00
|
|
|
ROOT = os.path.dirname(os.path.abspath(__file__))
|
2010-03-13 02:37:51 +03:00
|
|
|
if os.path.splitext(os.path.basename(__file__))[0] == 'cProfile':
|
|
|
|
if os.environ.get('ZAMBONI_PATH'):
|
|
|
|
ROOT = os.environ['ZAMBONI_PATH']
|
|
|
|
else:
|
|
|
|
print 'When using cProfile you must set $ZAMBONI_PATH'
|
|
|
|
sys.exit(2)
|
|
|
|
|
2010-01-29 22:32:20 +03:00
|
|
|
path = lambda *a: os.path.join(ROOT, *a)
|
|
|
|
|
2010-05-20 21:24:58 +04:00
|
|
|
prev_sys_path = list(sys.path)
|
|
|
|
|
2010-01-29 22:32:20 +03:00
|
|
|
site.addsitedir(path('apps'))
|
2010-09-18 04:07:13 +04:00
|
|
|
site.addsitedir(path('vendor/lib/python'))
|
2010-05-18 18:29:43 +04:00
|
|
|
|
2010-05-20 21:24:58 +04:00
|
|
|
# Move the new items to the front of sys.path. (via virtualenv)
|
|
|
|
new_sys_path = []
|
|
|
|
for item in list(sys.path):
|
|
|
|
if item not in prev_sys_path:
|
|
|
|
new_sys_path.append(item)
|
|
|
|
sys.path.remove(item)
|
|
|
|
sys.path[:0] = new_sys_path
|
|
|
|
|
2012-07-19 12:50:57 +04:00
|
|
|
|
2010-05-18 18:29:43 +04:00
|
|
|
# No third-party imports until we've added all our sitedirs!
|
2011-07-15 03:17:31 +04:00
|
|
|
from django.core.management import (call_command, execute_manager,
|
|
|
|
setup_environ)
|
2009-10-22 04:31:24 +04:00
|
|
|
|
2012-01-18 21:11:06 +04:00
|
|
|
# Figuring out what settings file to use.
|
|
|
|
# 1. Look first for the command line setting.
|
|
|
|
setting = None
|
2012-02-09 12:02:40 +04:00
|
|
|
if __name__ == '__main__':
|
2012-02-14 22:27:56 +04:00
|
|
|
for k, v in enumerate(sys.argv):
|
|
|
|
if v.startswith('--settings'):
|
|
|
|
setting = v.split('=')[1]
|
|
|
|
del sys.argv[k]
|
|
|
|
break
|
2012-01-18 21:11:06 +04:00
|
|
|
|
|
|
|
# 2. If not, find the env variable.
|
|
|
|
if not setting:
|
|
|
|
setting = os.environ.get('DJANGO_SETTINGS_MODULE', '')
|
|
|
|
|
|
|
|
# Django runserver does that double reload of installed settings, settings
|
|
|
|
# setting to zamboni.settings. We don't want to have zamboni on the path.
|
2012-03-02 07:52:55 +04:00
|
|
|
if setting.startswith(('zamboni', # typical git clone destination
|
|
|
|
'workspace', # Jenkins
|
|
|
|
'project', # vagrant VM
|
|
|
|
'freddo')):
|
2012-02-01 05:30:37 +04:00
|
|
|
setting = setting.split('.', 1)[1]
|
2012-02-01 04:44:36 +04:00
|
|
|
|
2012-02-03 02:19:12 +04:00
|
|
|
# The average Django user will have DJANGO_SETTINGS_MODULE set to settings
|
|
|
|
# for our purposes that means, load the default site, so if nothing is
|
|
|
|
# specified by now, use the default.
|
|
|
|
if setting in ('settings', ''):
|
|
|
|
setting = 'settings_local'
|
2012-01-18 21:11:06 +04:00
|
|
|
|
|
|
|
# Finally load the settings file that was specified.
|
2012-12-19 23:28:35 +04:00
|
|
|
from django.utils import importlib
|
|
|
|
settings = importlib.import_module(setting)
|
2012-01-18 21:11:06 +04:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = setting
|
2012-01-31 03:36:57 +04:00
|
|
|
|
2012-02-01 04:11:05 +04:00
|
|
|
if not settings.DEBUG:
|
|
|
|
warnings.simplefilter('ignore')
|
|
|
|
|
2012-01-31 03:36:57 +04:00
|
|
|
# The first thing execute_manager does is call `setup_environ`. Logging config
|
|
|
|
# needs to access settings, so we'll setup the environ early.
|
2009-12-16 02:53:21 +03:00
|
|
|
setup_environ(settings)
|
|
|
|
|
2011-02-02 01:23:53 +03:00
|
|
|
# Hardcore monkeypatching action.
|
|
|
|
import safe_django_forms
|
|
|
|
safe_django_forms.monkeypatch()
|
|
|
|
|
2011-04-21 00:59:02 +04:00
|
|
|
import session_csrf
|
|
|
|
session_csrf.monkeypatch()
|
|
|
|
|
2011-07-29 20:57:58 +04:00
|
|
|
# Fix jinja's Markup class to not crash when localizers give us bad format
|
|
|
|
# strings.
|
|
|
|
from jinja2 import Markup
|
|
|
|
mod = Markup.__mod__
|
|
|
|
trans_log = logging.getLogger('z.trans')
|
|
|
|
|
|
|
|
|
|
|
|
def new(self, arg):
|
|
|
|
try:
|
|
|
|
return mod(self, arg)
|
|
|
|
except Exception:
|
|
|
|
trans_log.error(unicode(self))
|
|
|
|
return ''
|
|
|
|
|
|
|
|
Markup.__mod__ = new
|
|
|
|
|
2012-02-09 00:06:47 +04:00
|
|
|
import djcelery
|
|
|
|
djcelery.setup_loader()
|
|
|
|
|
2012-01-31 03:36:57 +04:00
|
|
|
# Import for side-effect: configures our logging handlers.
|
|
|
|
# pylint: disable-msg=W0611
|
2012-02-10 04:46:00 +04:00
|
|
|
from lib.log_settings_base import log_configure
|
|
|
|
log_configure()
|
2009-12-16 02:53:21 +03:00
|
|
|
|
2012-01-31 04:29:36 +04:00
|
|
|
from lib.misc import safe_signals
|
2010-09-25 04:17:03 +04:00
|
|
|
safe_signals.start_the_machine()
|
2010-09-24 02:20:54 +04:00
|
|
|
|
2009-10-23 21:18:21 +04:00
|
|
|
|
2009-10-21 03:29:27 +04:00
|
|
|
if __name__ == "__main__":
|
2011-07-15 03:17:31 +04:00
|
|
|
# If product details aren't present, get them.
|
|
|
|
from product_details import product_details
|
|
|
|
if not product_details.last_update:
|
|
|
|
print 'Product details missing, downloading...'
|
|
|
|
call_command('update_product_details')
|
|
|
|
product_details.__init__() # reload the product details
|
|
|
|
|
2009-10-21 03:29:27 +04:00
|
|
|
execute_manager(settings)
|