1 6
from .celery import app as celery_app
2 6
import warnings
3 6
import os
4 6
import sys
5

6 6
__all__ = ['celery_app']
7

8 6
__version__ = '1.0'
9

10

11 6
def find_commands(management_dir):
12
    # Modified version of function from django/core/management/__init__.py.
13 0
    command_dir = os.path.join(management_dir, 'commands')
14 0
    commands = []
15 0
    try:
16 0
        for f in os.listdir(command_dir):
17 0
            if f.startswith('_'):
18 0
                continue
19 0
            elif f.endswith('.py') and f[:-3] not in commands:
20 0
                commands.append(f[:-3])
21 0
            elif f.endswith('.pyc') and f[:-4] not in commands:
22 0
                commands.append(f[:-4])
23 0
    except OSError:
24 0
        pass
25 0
    return commands
26

27

28 6
def prepare_env():
29
    # Hide DeprecationWarnings when running in production.  Need to first load
30
    # settings to apply our filter after Django's own warnings filter.
31 6
    from django.conf import settings
32 6
    if not settings.DEBUG:
33 6
        warnings.simplefilter('ignore', DeprecationWarning)
34
    # Monkeypatch Django find_commands to also work with .pyc files.
35 6
    import django.core.management
36 6
    django.core.management.find_commands = find_commands
37
    # Fixup sys.modules reference to django.utils.six to allow jsonfield to
38
    # work when using Django 1.4.
39 6
    import django.utils
40 6
    try:
41 6
        import django.utils.six
42 0
    except ImportError:
43 0
        import six
44 0
        sys.modules['django.utils.six'] = sys.modules['six']
45 0
        django.utils.six = sys.modules['django.utils.six']
46 0
        from django.utils import six # noqa
47
    # Disable capturing all SQL queries in memory when in DEBUG mode.
48 6
    if settings.DEBUG and not getattr(settings, 'SQL_DEBUG', True):
49 0
        from django.db.backends.base.base import BaseDatabaseWrapper as b
50 0
        from django.db.backends.utils import CursorWrapper
51 0
        b.make_debug_cursor = lambda self, cursor: CursorWrapper(cursor, self)
52

53
    # Use the default devserver addr/port defined in settings for runserver.
54 6
    default_addr = getattr(settings, 'DEVSERVER_DEFAULT_ADDR', '127.0.0.1')
55 6
    default_port = getattr(settings, 'DEVSERVER_DEFAULT_PORT', 8000)
56 6
    from django.core.management.commands import runserver as core_runserver
57 6
    original_handle = core_runserver.Command.handle
58

59 6
    def handle(self, *args, **options):
60 0
        if not options.get('addrport'):
61 0
            options['addrport'] = '%s:%d' % (default_addr, int(default_port))
62 0
        elif options.get('addrport').isdigit():
63 0
            options['addrport'] = '%s:%d' % (
64
                default_addr,
65
                int(options['addrport'])
66
            )
67 0
        return original_handle(self, *args, **options)
68

69 6
    core_runserver.Command.handle = handle
70

71

72 6
def manage():
73 0
    prepare_env()
74
    # Now run the command (or display the version).
75 0
    from django.conf import settings
76 0
    from django.core.management import execute_from_command_line
77 0
    if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'):
78 0
        sys.stdout.write('%s\n' % __version__)
79
    # If running as a user without permission to read settings, display an
80
    # error message.  Allow --help to still work.
81 0
    elif settings.SECRET_KEY == 'permission-denied':
82 0
        if (
83
            len(sys.argv) == 1
84
            or len(sys.argv) >= 2
85
            and sys.argv[1] in ('-h', '--help', 'help')
86
        ):
87 0
            execute_from_command_line(sys.argv)
88 0
            sys.stdout.write('\n')
89 0
        prog = os.path.basename(sys.argv[0])
90 0
        sys.stdout.write('Permission denied: %s must be run as root.\n' % prog)
91 0
        sys.exit(1)
92
    else:
93 0
        execute_from_command_line(sys.argv)

Read our documentation on viewing source code .

Loading