Permalink
Switch branches/tags
v0.0.1 test-tag phone-number-messaging-migration logs-messaging-migration keyword-messaging-migration domain-default-backend-messaging-migration ben ben-ben ben-ben-ben backend-messaging-migration aben-ben-ben 2017-12-12_01.00-swiss-deploy 2017-12-11_21.28-production-deploy 2017-12-11_21.28-enikshay-deploy 2017-12-11_20.24-icds-deploy 2017-12-11_16.37-staging-deploy 2017-12-11_09.59-enikshay-deploy 2017-12-08_21.52-softlayer-deploy 2017-12-08_21.51-production-deploy 2017-12-08_20.34-icds-deploy 2017-12-08_15.44-staging-deploy 2017-12-08_13.41-production-deploy 2017-12-08_11.28-production-deploy 2017-12-08_00.55-production-deploy 2017-12-08_00.36-enikshay-deploy 2017-12-07_20.24-icds-deploy 2017-12-07_18.42-staging-deploy 2017-12-07_16.14-staging-deploy 2017-12-06_21.46-icds-deploy 2017-12-06_05.47-pna-deploy 2017-12-05_20.47-softlayer-deploy 2017-12-05_19.33-icds-deploy 2017-12-04_20.39-icds-deploy 2017-12-04_18.26-staging-deploy 2017-12-04_17.09-staging-deploy 2017-12-01_23.22-staging-deploy 2017-12-01_19.29-staging-deploy 2017-12-01_18.46-icds-deploy 2017-12-01_17.32-staging-deploy 2017-12-01_01.56-icds-deploy 2017-11-30_22.54-icds-deploy 2017-11-30_21.36-enikshay-deploy 2017-11-30_20.34-icds-deploy 2017-11-30_20.10-staging-deploy 2017-11-30_15.53-staging-deploy 2017-11-29_22.19-icds-deploy 2017-11-29_21.36-production-deploy 2017-11-29_20.51-softlayer-deploy 2017-11-29_18.18-staging-deploy 2017-11-29_17.27-staging-deploy 2017-11-29_10.33-production-deploy 2017-11-29_03.16-staging-deploy 2017-11-29_02.40-staging-deploy 2017-11-28_22.58-production-deploy 2017-11-28_22.58-enikshay-deploy 2017-11-28_21.35-staging-deploy 2017-11-28_20.48-icds-deploy 2017-11-28_20.12-icds-deploy 2017-11-28_18.03-pna-deploy 2017-11-28_18.02-icds-deploy 2017-11-28_17.30-staging-deploy 2017-11-28_17.02-staging-deploy 2017-11-28_09.16-staging-deploy 2017-11-27_20.10-icds-deploy 2017-11-26_14.27-enikshay-deploy 2017-11-21_15.03-staging-deploy 2017-11-20_23.24-icds-deploy 2017-11-17_20.41-icds-deploy 2017-11-16_20.41-icds-deploy 2017-11-16_14.36-staging-deploy 2017-11-15_22.29-softlayer-deploy 2017-11-15_22.29-production-deploy 2017-11-15_21.39-production-deploy 2017-11-15_21.39-enikshay-deploy 2017-11-15_20.06-icds-deploy 2017-11-14_22.38-staging-deploy 2017-11-14_21.47-staging-deploy 2017-11-14_21.47-icds-deploy 2017-11-14_21.31-staging-deploy 2017-11-14_20.55-production-deploy 2017-11-14_20.53-enikshay-deploy 2017-11-14_14.42-production-deploy 2017-11-14_05.16-pna-deploy 2017-11-13_21.09-icds-deploy 2017-11-13_20.32-staging-deploy 2017-11-13_20.12-softlayer-deploy 2017-11-13_20.12-production-deploy 2017-11-13_20.12-enikshay-deploy 2017-11-13_19.54-staging-deploy 2017-11-13_19.36-swiss-deploy 2017-11-11_10.02-staging-deploy 2017-11-11_09.44-staging-deploy 2017-11-11_09.19-staging-deploy 2017-11-11_08.54-staging-deploy 2017-11-10_20.01-enikshay-deploy 2017-11-10_20.00-softlayer-deploy 2017-11-10_20.00-production-deploy 2017-11-10_15.53-staging-deploy 2017-11-10_15.14-icds-deploy 2017-11-09_23.50-staging-deploy
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 134 lines (103 sloc) 4.13 KB
#!/usr/bin/env python
from __future__ import absolute_import
import sys
import os
import mimetypes
from collections import namedtuple
import django
GeventCommand = namedtuple('GeventCommand', 'command contains')
def _set_source_root_parent(source_root_parent):
"""
add everything under `source_root_parent` to the list of source roots
e.g. if you call this with param 'submodules'
and you have the file structure
project/
submodules/
foo-src/
foo/
bar-src/
bar/
(where foo and bar are python modules)
then foo and bar would become top-level importable
"""
filedir = os.path.dirname(__file__)
submodules_list = os.listdir(os.path.join(filedir, source_root_parent))
for d in submodules_list:
if d == "__init__.py" or d == '.' or d == '..':
continue
sys.path.insert(1, os.path.join(filedir, source_root_parent, d))
sys.path.append(os.path.join(filedir, source_root_parent))
def _set_source_root(source_root):
filedir = os.path.dirname(__file__)
sys.path.insert(1, os.path.join(filedir, source_root))
# HACK monkey-patch django setup to prevent second setup by django_nose
def _setup_once(*args, **kw):
if not hasattr(_setup_once, "done"):
_setup_once.done = True
_setup_once.setup(*args, **kw)
_setup_once.setup = django.setup
django.setup = _setup_once
def init_hq_python_path():
_set_source_root_parent('submodules')
_set_source_root(os.path.join('corehq', 'ex-submodules'))
_set_source_root(os.path.join('custom', '_legacy'))
def _should_patch_gevent(args, gevent_commands):
should_patch = False
for gevent_command in gevent_commands:
should_patch = args[1] == gevent_command.command
if gevent_command.contains:
should_patch = should_patch and gevent_command.contains in ' '.join(args)
if should_patch:
break
return should_patch
def set_default_settings_path(argv):
if len(argv) > 1 and argv[1] == 'test':
module = 'testsettings'
else:
module = 'settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", module)
def patch_jsonfield():
"""Patch the ``to_python`` method of JSONField
See https://github.com/bradjasper/django-jsonfield/pull/173 for more details
"""
import six
import json
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
def to_python(self, value):
if isinstance(value, six.string_types):
try:
return json.loads(value, **self.load_kwargs)
except ValueError:
raise ValidationError(_("Enter valid JSON"))
return value
JSONField.to_python = to_python
if __name__ == "__main__":
init_hq_python_path()
# important to apply gevent monkey patches before running any other code
# applying this later can lead to inconsistencies and threading issues
# but compressor doesn't like it
# ('module' object has no attribute 'poll' which has to do with
# gevent-patching subprocess)
GEVENT_COMMANDS = (
GeventCommand('mvp_force_update', None),
GeventCommand('run_gunicorn', None),
GeventCommand('preindex_everything', None),
GeventCommand('prime_views', None),
GeventCommand('ptop_preindex', None),
GeventCommand('sync_prepare_couchdb_multi', None),
GeventCommand('sync_couch_views', None),
GeventCommand('celery', '-P gevent'),
GeventCommand('populate_form_date_modified', None),
)
if len(sys.argv) > 1 and _should_patch_gevent(sys.argv, GEVENT_COMMANDS):
from restkit.session import set_session; set_session("gevent")
from gevent.monkey import patch_all; patch_all(subprocess=True)
from psycogreen.gevent import patch_psycopg; patch_psycopg()
# workaround for https://github.com/smore-inc/tinys3/issues/33
mimetypes.init()
patch_jsonfield()
set_default_settings_path(sys.argv)
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)