예제 #1
0
파일: utils.py 프로젝트: miki725/mro-tools
def initialize(pre, django, django_configurations, **kwargs):
    if django:
        import django

        django.setup()

    if django_configurations:
        import configurations

        configurations.setup()

    if pre:
        exec(pre)
예제 #2
0
파일: manage.py 프로젝트: kaday506s/Profile
def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
    os.environ.setdefault('DJANGO_CONFIGURATION', 'DevLocal')
    sys.path.append('apps/')

    configurations.setup()
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?") from exc
    execute_from_command_line(sys.argv)
예제 #3
0
def main():
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "divisao-contas-api.config")
    os.environ.setdefault("DJANGO_CONFIGURATION", "Local")

    try:
        import configurations
        configurations.setup()
        from configurations.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django  # noqa
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)
예제 #4
0
파일: tests.py 프로젝트: advait2498/ft-api
import configurations
import django
import os
import random

os.environ['DJANGO_SETTINGS_MODULE'] = 'ft_api.settings'
# setup the configuration local
os.environ['DJANGO_CONFIGURATION'] = 'Local'
configurations.setup()
django.setup()

from rest_framework_signature.helpers import RestFrameworkSignatureTestClass
from rest_framework import status

from ft_api.test.helpers import DataGenerator


class FitnessPlanTests(RestFrameworkSignatureTestClass):

    def test_get(self):
        # arrange
        fitness_plan = DataGenerator.set_up_fitness_plan()
        url = '/fitnessPlans/{0}'.format(fitness_plan.id)
        headers = self.get_headers(url)

        # act
        result = self.api_client.get(url, format='json', **headers)

        # assert
        self.assertEqual(result.status_code, status.HTTP_200_OK)
        self.assertEqual(result.data['id'], fitness_plan.id)
예제 #5
0
    def handle(self, *args, **options):
        for arg in args:
            k, v = arg.split('=')
            if k == 'http':
                if self.http_port:
                    self.http_port = v
            elif k == 'socket':
                self.http_port = None
                self.socket_addr = v

        # load the Django WSGI handler
        os.environ.setdefault('UWSGI_MODULE', '%s.wsgi' % django_project)
        # DJANGO settings
        if options['settings']:
            os.environ['DJANGO_SETTINGS_MODULE'] = options['settings']
        else:
            os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s.settings' % django_project)

        # set protocol as uwsgi
        os.environ.setdefault('UWSGI_PROTOCOL', 'uwsgi')

        # bind the http server to the default port
        if self.http_port:
            os.environ['UWSGI_HTTP_SOCKET'] = ':%s' % self.http_port
        elif self.socket_addr:
            os.environ['UWSGI_UWSGI_SOCKET'] = self.socket_addr
            os.environ.setdefault('UWSGI_CHMOD_SOCKET', '664')
        # set process names
        os.environ.setdefault('UWSGI_AUTO_PROCNAME', 'true')
        os.environ.setdefault('UWSGI_PROCNAME_PREFIX_SPACED', '[uWSGI %s]' % django_project)
        # remove sockets/pidfile at exit
        os.environ.setdefault('UWSGI_VACUUM', 'true')
        # retrieve/set the PythonHome
        os.environ.setdefault('UWSGI_VIRTUALENV', sys.prefix)
        # add project to python path
        os.environ.setdefault('UWSGI_PP', root)

        os.environ.setdefault('UWSGI_POST_BUFFERING', '1048576')
        os.environ.setdefault('UWSGI_RELOAD_ON_RSS', '300')
        # increase buffer size a bit
        os.environ.setdefault('UWSGI_BUFFER_SIZE', '65535')
        # some additions required by newrelic
        os.environ.setdefault('UWSGI_ENABLE_THREADS', 'true')
        os.environ.setdefault('UWSGI_LAZY_APPS', 'true')
        os.environ.setdefault('UWSGI_SINGLE_INTERPRETER', 'true')
        os.environ.setdefault('UWSGI_AUTOLOAD', 'true')
        # set 12 workers and cheaper to number of cpus
        os.environ.setdefault('UWSGI_WORKERS', '12')
        os.environ.setdefault('UWSGI_CHEAPER', str(multiprocessing.cpu_count()))
        # enable the master process
        os.environ.setdefault('UWSGI_MASTER', 'true')

        os.environ.setdefault('UWSGI_NO_ORPHANS', 'true')
        os.environ.setdefault('UWSGI_MEMORY_REPORT', 'true')
        os.environ.setdefault('UWSGI_DISABLE_LOGGING', 'true')

        # set harakiri
        os.environ.setdefault('UWSGI_HARAKIRI', '60')
        os.environ.setdefault('UWSGI_HARAKIRI_VERBOSE', 'true')

        # set uid and gid
        os.environ.setdefault('UWSGI_UID', str(os.getuid()))
        os.environ.setdefault('UWSGI_GID', str(os.getgid()))
        # TODO: Figure out cache
        os.environ.setdefault('UWSGI_CACHE2', 'name=%s,items=20000,keysize=128,blocksize=4096' % django_project)
        if settings.DEBUG:
            if apps.is_installed('configurations'):
                os.environ.setdefault('DJANGO_CONFIGURATION', 'Development')
                import configurations
                configurations.setup()
            # map and serve static files
            os.environ.setdefault('UWSGI_STATIC_MAP', '%s=%s' % (settings.STATIC_URL, settings.STATIC_ROOT))
            os.environ.setdefault('UWSGI_PY_AUTORELOAD', '2')
        # run spooler for mail task
        if 'django_uwsgi' in settings.EMAIL_BACKEND:
            os.environ.setdefault('UWSGI_SPOOLER', '/tmp')
            os.environ.setdefault('UWSGI_SPOOLER_IMPORT', 'django_uwsgi.tasks')
        # exec the uwsgi binary
        if apps.ready:
            os.execvp('uwsgi', ('uwsgi',))
예제 #6
0
파일: conftest.py 프로젝트: CDE-UNIBE/qcat
"""
Use this file to setup envdir and django-configurations, as this works nicely with PyCharms
integrated (clickable) test feature.
"""

import os
import envdir
import configurations
import pytest

envdir.read(os.path.join(os.path.dirname(__file__), 'envs'))
os.environ.__setitem__('DJANGO_CONFIGURATION', 'TestDefaultSite')
configurations.setup()


@pytest.fixture
def es(request):
    """
    In order to allow multiple Elasticsearch indices when running tests in
    parallel, overwrite ES_INDEX_PREFIX settings for each test function
    according to its slave id.

    Usage for tests that require Elasticsearch:
    @pytest.mark.usefixtures('es')
    """
    from django.conf import settings
    from search.index import get_elasticsearch
    from search.search import get_indices_alias

    # Clear lru_cache of Elasticsearch indices.
    get_indices_alias.cache_clear()
예제 #7
0
def pytest_configure():
    os.environ.setdefault('DJANGO_CONFIGURATION', 'Development')
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'moviebase.settings')
    configurations.setup()
예제 #8
0
    def handle(self, *args, **options):
        for arg in args:
            k, v = arg.split("=")
            if k == "http":
                if self.http_port:
                    self.http_port = v
            elif k == "socket":
                self.http_port = None
                self.socket_addr = v

        # load the Django WSGI handler
        os.environ["UWSGI_MODULE"] = "%s.wsgi" % django_project
        # DJANGO settings
        if options["settings"]:
            os.environ["DJANGO_SETTINGS_MODULE"] = options["settings"]
        else:
            os.environ["DJANGO_SETTINGS_MODULE"] = "%s.settings" % django_project

        # set protocol as uwsgi
        os.environ["UWSGI_PROTOCOL"] = "uwsgi"

        # bind the http server to the default port
        if self.http_port:
            os.environ["UWSGI_HTTP_SOCKET"] = ":%s" % self.http_port
        elif self.socket_addr:
            os.environ["UWSGI_UWSGI_SOCKET"] = self.socket_addr
            os.environ["UWSGI_CHMOD_SOCKET"] = "664"
        # set process names
        os.environ["UWSGI_AUTO_PROCNAME"] = "true"
        os.environ["UWSGI_PROCNAME_PREFIX_SPACED"] = "[uWSGI %s]" % django_project
        # remove sockets/pidfile at exit
        os.environ["UWSGI_VACUUM"] = "true"
        # retrieve/set the PythonHome
        os.environ["UWSGI_VIRTUALENV"] = sys.prefix
        # add project to python path
        os.environ["UWSGI_PP"] = root

        os.environ["UWSGI_POST_BUFFERING"] = "1048576"
        os.environ["UWSGI_RELOAD_ON_RSS"] = "300"
        # increase buffer size a bit
        os.environ["UWSGI_BUFFER_SIZE"] = "65535"
        # some additions required by newrelic
        os.environ["UWSGI_ENABLE_THREADS"] = "true"
        os.environ["UWSGI_LAZY_APPS"] = "true"
        os.environ["UWSGI_SINGLE_INTERPRETER"] = "true"
        os.environ["UWSGI_AUTOLOAD"] = "true"
        # set 12 workers and cheaper to number of cpus
        os.environ["UWSGI_WORKERS"] = "12"
        os.environ["UWSGI_CHEAPER"] = str(multiprocessing.cpu_count())
        # enable the master process
        os.environ["UWSGI_MASTER"] = "true"

        os.environ["UWSGI_NO_ORPHANS"] = "true"
        os.environ["UWSGI_MEMORY_REPORT"] = "true"
        os.environ["UWSGI_DISABLE_LOGGING"] = "true"

        # set harakiri
        os.environ["UWSGI_HARAKIRI"] = "60"
        os.environ["UWSGI_HARAKIRI_VERBOSE"] = "true"

        # set uid and gid
        os.environ["UWSGI_UID"] = str(os.getuid())
        os.environ["UWSGI_GID"] = str(os.getgid())
        # TODO: Figure out cache
        os.environ["UWSGI_CACHE2"] = "name=%s,items=20000,keysize=128,blocksize=4096" % django_project
        if settings.DEBUG:
            if apps.is_installed("configurations"):
                os.environ.setdefault("DJANGO_CONFIGURATION", "Development")
                import configurations

                configurations.setup()
            # map and serve static files
            os.environ["UWSGI_STATIC_MAP"] = "%s=%s" % (settings.STATIC_URL, settings.STATIC_ROOT)
            os.environ["UWSGI_PY_AUTORELOAD"] = "2"
        # run spooler for mail task
        if "django_uwsgi" in settings.EMAIL_BACKEND:
            os.environ["UWSGI_SPOOLER"] = "/tmp"
            os.environ["UWSGI_SPOOLER_IMPORT"] = "django_uwsgi.tasks"
        # exec the uwsgi binary
        if apps.ready:
            os.execvp("uwsgi", ("uwsgi",))
예제 #9
0
    def handle(self, *args, **options):
        for arg in args:
            k, v = arg.split('=')
            if k == 'http':
                if self.http_port:
                    self.http_port = v
            elif k == 'socket':
                self.http_port = None
                self.socket_addr = v

        # load the Django WSGI handler
        os.environ['UWSGI_MODULE'] = '%s.wsgi' % django_project
        # DJANGO settings
        if options['settings']:
            os.environ['DJANGO_SETTINGS_MODULE'] = options['settings']
        else:
            os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % django_project

        # set protocol as uwsgi
        os.environ['UWSGI_PROTOCOL'] = 'uwsgi'

        # bind the http server to the default port
        if self.http_port:
            os.environ['UWSGI_HTTP_SOCKET'] = ':%s' % self.http_port
        elif self.socket_addr:
            os.environ['UWSGI_UWSGI_SOCKET'] = self.socket_addr
            os.environ['UWSGI_CHMOD_SOCKET'] = '664'
        # set process names
        os.environ['UWSGI_AUTO_PROCNAME'] = 'true'
        os.environ['UWSGI_PROCNAME_PREFIX_SPACED'] = '[uWSGI %s]' % django_project
        # remove sockets/pidfile at exit
        os.environ['UWSGI_VACUUM'] = 'true'
        # retrieve/set the PythonHome
        os.environ['UWSGI_VIRTUALENV'] = sys.prefix
        # add project to python path
        os.environ['UWSGI_PP'] = root

        os.environ['UWSGI_POST_BUFFERING'] = '1048576'
        os.environ['UWSGI_RELOAD_ON_RSS'] = '300'
        # increase buffer size a bit
        os.environ['UWSGI_BUFFER_SIZE'] = '65535'
        # some additions required by newrelic
        os.environ['UWSGI_ENABLE_THREADS'] = 'true'
        os.environ['UWSGI_LAZY_APPS'] = 'true'
        os.environ['UWSGI_SINGLE_INTERPRETER'] = 'true'
        os.environ['UWSGI_AUTOLOAD'] = 'true'
        # set 12 workers and cheaper to number of cpus
        os.environ['UWSGI_WORKERS'] = '12'
        os.environ['UWSGI_CHEAPER'] = str(multiprocessing.cpu_count())
        # enable the master process
        os.environ['UWSGI_MASTER'] = 'true'

        os.environ['UWSGI_NO_ORPHANS'] = 'true'
        os.environ['UWSGI_MEMORY_REPORT'] = 'true'
        os.environ['UWSGI_DISABLE_LOGGING'] = 'true'

        # set harakiri
        os.environ['UWSGI_HARAKIRI'] = '60'
        os.environ['UWSGI_HARAKIRI_VERBOSE'] = 'true'

        # set uid and gid
        os.environ['UWSGI_UID'] = str(os.getuid())
        os.environ['UWSGI_GID'] = str(os.getgid())
        # TODO: Figure out cache
        os.environ['UWSGI_CACHE2'] = 'name=%s,items=20000,keysize=128,blocksize=4096' % django_project
        if settings.DEBUG:
            if apps.is_installed('configurations'):
                os.environ.setdefault('DJANGO_CONFIGURATION', 'Development')
                import configurations
                configurations.setup()
            # map and serve static files
            os.environ['UWSGI_STATIC_MAP'] = '%s=%s' % (settings.STATIC_URL, settings.STATIC_ROOT)
            os.environ['UWSGI_PY_AUTORELOAD'] = '2'
        # run spooler for mail task
        if 'django_uwsgi' in settings.EMAIL_BACKEND:
            os.environ['UWSGI_SPOOLER'] = '/tmp'
            os.environ['UWSGI_SPOOLER_IMPORT'] = 'django_uwsgi.task'
        # exec the uwsgi binary
        if apps.ready:
            os.execvp('uwsgi', ('uwsgi',))
예제 #10
0
@signals.setup_logging.connect
def setup_celery_logging(**kwargs):
    pass


name = 'worker'
log = build_colorized_logger(
    name=name)


# Required load order for backend workers
import configurations  # noqa
os.environ.setdefault(
    "DJANGO_SETTINGS_MODULE",
    "drf_network_pipeline.settings")
os.environ.setdefault(
    "DJANGO_CONFIGURATION",
    "Development")
configurations.setup()  # noqa
import django  # noqa

app = Celery(
    "drf_network_pipeline")

CELERY_TIMEZONE = "UTC"

app.config_from_object(
    "django.conf:settings",
    namespace="CELERY")
app.autodiscover_tasks()
예제 #11
0
from __future__ import absolute_import
from django.conf import settings
import os, configurations

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'identity.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Development')

try: configurations.setup()
except:
    import traceback
    traceback.print_exc()

if settings.USE_CELERY:
    # This will make sure the app is always imported when
    # Django starts so that shared_task will use this app.
    from .celery import app as celery_app
예제 #12
0
def pytest_configure(config):
    os.environ['DJANGO_CONFIGURATION'] = 'Test'
    os.environ['DJANGO_SETTINGS_MODULE'] = '{{project_name}}.settings'
    configurations.setup()