Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 163 lines (129 sloc) 4.629 kb
#!/usr/bin/env python
import imp
import logging
import os
import site
import sys
import warnings
# Bug 775430
#
# runs pymysql instead of python-mysqldb
# the proper way to do this is to create
# a pymysql backend in Django itself
#
# Will do cleaner if the gevent stack works correctly
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
ROOT = os.path.dirname(os.path.abspath(__file__))
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)
path = lambda *a: os.path.join(ROOT, *a)
prev_sys_path = list(sys.path)
site.addsitedir(path('apps'))
site.addsitedir(path('vendor'))
site.addsitedir(path('vendor/lib/python'))
# 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
# No third-party imports until we've added all our sitedirs!
from django.core.management import (call_command, execute_manager,
setup_environ)
# Figuring out what settings file to use.
# 1. Look first for the command line setting.
setting = None
if __name__ == '__main__':
for k, v in enumerate(sys.argv):
if v.startswith('--settings'):
setting = v.split('=')[1]
del sys.argv[k]
break
# 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.
if setting.startswith(('zamboni', # typical git clone destination
'workspace', # Jenkins
'project', # vagrant VM
'freddo')):
setting = setting.split('.', 1)[1]
# 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'
# Finally load the settings file that was specified.
res = imp.find_module(setting)
settings = imp.load_module(setting, *res)
os.environ['DJANGO_SETTINGS_MODULE'] = setting
# Bug 775430
try:
import pymysql
# a few conversions functions glitches
# looks like pymysql is a tad different in his
# typecast_* function
def _with_more_args(function):
def __with_more_args(data, *args):
if len(args) > 0:
data = args[-1]
return function(data)
return __with_more_args
from pymysql.constants import FIELD_TYPE
from django.db.backends.mysql.base import django_conversions
from django.db.backends import util
django_conversions.update({
FIELD_TYPE.TIME: _with_more_args(util.typecast_time),
FIELD_TYPE.DECIMAL: _with_more_args(util.typecast_decimal),
FIELD_TYPE.NEWDECIMAL: _with_more_args(util.typecast_decimal),
})
except ImportError:
pass
if not settings.DEBUG:
warnings.simplefilter('ignore')
# The first thing execute_manager does is call `setup_environ`. Logging config
# needs to access settings, so we'll setup the environ early.
setup_environ(settings)
# Hardcore monkeypatching action.
import safe_django_forms
safe_django_forms.monkeypatch()
import session_csrf
session_csrf.monkeypatch()
# 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
import djcelery
djcelery.setup_loader()
# Import for side-effect: configures our logging handlers.
# pylint: disable-msg=W0611
from lib.log_settings_base import log_configure
log_configure()
from lib.misc import safe_signals
safe_signals.start_the_machine()
if __name__ == "__main__":
# 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
execute_manager(settings)
Jump to Line
Something went wrong with that request. Please try again.